Fix SD card that cannot be formatted

Golden Rule #1

As soon as an SD card [or USB stick] starts to play up - bin it. They're not worth the effort once they error.

I go through literally hundreds of them for work. Low write count, high read count.

If they error once, they will error again. Quality control on them is, let's say… variable.

Some of them have a controller chip that will permanently lock them to read only if they detect a write error, as a preservation measure. There is no way to unlock them once this happens.

Golden Rule #2

Don't use them to store anything valuable.

Edit:
If the data on an SD card was truly valuable, it is theoretically possible to replace the controller chip, or even directly access the memory itself. This service can be performed by data recovery specialists, but they charge a lot for their efforts & still can make no guarantees.

Rules 1 & 2 are still 'best practise'