According to the show's model-maker, the asteroid hit the Red Dwarf significantly before everyone died.
"Rob and Doug didn't want it to look like a sophisticated spaceship –
they wanted it to look like something that had been around for
donkey's years," recalled Wragg of his brief. "A meteorite had
embedded itself in it – so they left it there!"
Peter Wragg: Designer best known for the 'Red Dwarf' spaceship
and from the same interview
“Rob and Doug had this idea about the ram scoop at the front which
sucked meteorites, etc. in; [in line with] the fact that it was a
mining vessel.“ Thus, it’s clear that despite the original concept of
the embedded asteroid being used for mining, the final model was built
with the idea that it had been an accidental strike.
The Red Dwarf FAQ
This was also addressed in the Red Dwarf book "Infinity Welcomes Careful Drivers".
A huge, shadowy carbuncle jutted out a mile or so from the red
monster's belly - a small moon, torn out of orbit, had flung itself
into the ship's solar plexus and was now embedded in the hull, hanging
there like a giant stone leech.
Other, lower canon interpretations (mostly from concept art stills and interviews) are discussed in detail here including the idea that the asteroid is being mined and that it was intentionally captured.