How do you restore an Android device with a locked bootloader?

I’m sorry if this is a stupid question, but I couldn’t find an answer for this. Having only had experience with Nexus devices, I’m wondering how one goes about "restoring" a phone with a locked bootloader.

Every time a new version of Android has come out I have flashed the new version to my Nexus 4/7. Is it possible to flash an image to a Moto X, GS4, HTC One, etc? If not, what do you do if a reset doesn’t fix a weird software problem?

Thanks, and again apologies if this is a stupid question.