Copy security code from Message alert stopped working

Whenever I received a security code to log into for example a banking website, I could long-press the message alert to copy the code and paste it into the webpage. Now when I long-press it throws an error about it being read-only. How do I get this great feature working again?

It mysteriously works again.

And now it doesn’t again.

However if I swipe down from the top to see all alerts, I can copy the code from there.