A mechanical hard drive could at least theoretically have a physical lock attached to the drive head which prevents it from approaching the platters if it is engaged.
Back in the EPROM days, that was easy, just don’t supply 25V or whatever.
Modern flash still needs those high voltages but generates it on-chip via charge pumps. If your read-only switch physically disconnected the charge pumps, you would have read-only flash.
Probably a method to retrofit write/erase protection would be to just do power analysis and cap the current the flash chip can receive. Or shut it down if that works for you.
Not sure if they’re intelligent enough to run their charge pumps slower under compromised electrical conditions. Or if they’ll go haywire if they can’t do idle-time wear levelling/block erases.
Edit: I think I’m wrong here and high voltage is needed for both.
If there is a way to make them writable via software, that would be very interesting (and dangerous).
... and you could absolutely build similar functionality into a flash chip. But most likely you can't actually buy such chips, at least not with any real capacity.