It sounds like the pin configuration in the firmware you flashed doesn't match your hardware. Heaters should never be on by default and M140 S0 should always turn off current to the bed. What you describe sounds like the firmware is sending power to a pin that it believes is something other than what it is, either because the bed is on a fan pin (like D9) or because the firmware thinks D8 is something other than the heated bed.
If it worked before, your original firmware was configured to match how your board was wired, specifically which pins were mapped to what hardware. If you're confident that the new firmware pin configuration is correct, you can ignore this theory. Otherwise you should nail down which D8/D9/D10 pin maps to what hardware and resolve the mismatch.
On RAMPS, pins 8, 9 and 10 are typically used to control fans, hotends and heated beds and you define this behavior in configuration.h. If you flashed from source you should review configuration.h and ensure it matches your hardware. This likely means setting the
MOTHERBOARD to the value that matches how pins 8/9/10 are wired. See this section (or something similar) in
configuration.h to get started:
// The following define selects which electronics board you have.
// Please choose the name from boards.h that matches your setup
#define MOTHERBOARD BOARD_RAMPS_14_EFB