Bootloader does not stay locked

My stock, un-rooted, Nexus 4 decided to stop working today. It just got stuck at the X loading over and over again. I'm trying to flash a recovery and fix this, but I can't get the bootloader to unlock. I type in fastboot oem unlock, which gives me the option to unlock. As soon as I reset however, it becomes locked again automatically.

I've also tried flashing recover right after unlocking, but it gives me an error and says remote: flash write failure.

XDA Developers was founded by developers, for developers. It is now a valuable resource for people who want to make the most of their mobile devices, from customizing the look and feel to adding new functionality.Are you a developer?