It would help if you told us which Mac you have and what year it was made.
Also, is it a platter-based hard drive or an SSD?
You probably need to "boot externally" (that means from an external hard drive or USB flashdrive installer), and try to re-initialize the internal hard drive that way.
I'm wondering if the reason the hard drive "locked" is due to a drive failure. I seem to recall that (if it's an SSD) it can "fail into read-only mode". You can read from the drive, but can't write to it.
Again, what Mac and what kind of drive?