Accessing stm32 registers via structs in GCC
Typically memory mapped hardware special function registers must be declared volatile so that the hardware knows that something may need or alter their state beyond the local thread of execution - otherwise it is free to cache values in registers or neglect to even compute apparently unused ones at all.

On the STM32, certain SFRs may also be restricted to a particular width of access.

If what you are trying to do is legitimate, there is likely already a suitable definition within the vendor (or alternate) driver or HAL files.  And even if there isn't, you can learn a lot by reading those to see how something simple like a GPIO block is declared.

Of course it's also possible that there is something specifically wrong with the particular operation you are trying to perform - for example, that might not be writable, or only be meaningfully writable when the hardware is in a particular state, which the debugger lucks out in achieving while your program usually does not.