Hard to say what is the rootcause, but I also fased strange things a time ago. Where the IDE absolutly ignored changes in code and only upload still one same binary file. That is why I wrote about Clean Build above.
KSC upload wrong binary - Keil Studio - Arm Mbed OS support forum
So I usually check the log and when there is no info about compilation of changed file not pressend (and I know I made some changes) then I know something is wrong.
compile main.cpp
Build succeeded
BR, Jan