First reason. Mechanical. Only for full-size SD cards. The slider on the edge of the SD card has no function within the card; it is just a notch which will be felt by a lever in the slot, and the host determines based upon the position of the lever, whether to permit writing. If the slider has been knocked down in a bag, it prevents the card from being written; if the slider has broken off, or the lever has bent, then either all cards will fail to be written, or none will. Try moving the slider upward, try using a different slot, and if you still get the message after trying a known-good reader with the switch moved up, then the issue is somewhere else.
Second reason. Relates to microSD cards in adapters. The adapter itself contains a slider, and SanDisk's note about locked microSD cards states that when placing the microSD card in a host the slider may have slid over to the locked position due to looseness of the adapter lock switch, and that the adapter needs to be replaced. A microSD card has no slider of its own. Try inserting the microSD card into a reader with a microSD slot. If the card can be written to in a known-good reader/slot, then the problem was with the adapter, and your microSD card is fine.
And the third is the card. As you use flash memory to write information to the card, it eventually wears out. And like other manufacturers, SanDisk's card has extra “spare” blocks of flash memory that are used to replace failed areas. SanDisk's notes say their card keeps two copies of its own data on two separate blocks. If corruption occurs on both copies, the card will be put in read-only “write-protect” mode. At some point in time, the manufacturer's controller firmware will also cause the drive to automatically go into write-protection mode to prevent losing data if the number of “good” blocks left on the card is lower than the preset threshold. All manufacturers' controllers work similarly, even though they don't always mention doing so. This type of block lock is permanently built-in to the controller's firmware. A user cannot turn it off. There is a reason for it: the card can no longer promise to keep what it is given. The card will still give you back what it already has, for a while. Therefore, copy everything off the card immediately using a card reader connected to your computer. If the card does not read quickly enough or if it disconnects during the copying process, then send it to us. We image it on the bench in short passes, with the power cycled between them.
The forum fixes are worth a paragraph because they cost time. diskpart's “attributes disk clear readonly” clears a flag Windows keeps about a disk; it does nothing to a lock the controller set. The registry key under StorageDevicePolicies does the same. The makers' format tools try to rebuild the card's table from scratch and, on a card that has locked itself, fail with Windows was unable to complete the format, which is its own page. None of them unlock the card; every attempt powers a card at the end of its life once more.