Yes, Diesel Engines Can Run Backwards – Here's What Can Happen If They Do
A diesel engine is simultaneously incredibly simple and incredibly violent, using compression as a means of ignition. This is because of the properties of diesel fuel: Namely, diesel is less volatile and has a higher density than gasoline, which means it's harder to ignite. That's why diesel engines operate using compression rather than spark plugs in gasoline engines. However, there's a bizarre side effect that comes from an engine which operates through mechanical means rather than something external. If all the conditions are met (compression, fuel, and heat), then the engine will run just fine in a configuration that's not intended.
That's why a diesel engine can run backwards. What does it mean to say that an engine is running "backwards?" In short, this means that an engine's crankshaft is spinning the wrong way around, the crankshaft being the main nerve center of the engine. It's the shaft that all the pistons are joined to, and it's designed to spin in one direction only. Spinning it the opposite direction means that the entire intake and exhaust process is reversed; a car running in such a condition is actually pulling air from the tailpipe, through the muffler and headers, combusting it, and expelling it out the air intake.
This is, of course, bad for several reasons: Namely, an engine is designed with precise timing going one way, it can damage or clog up various components with soot, and lubrication systems might not work properly in the opposite direction. There are actually some two-stroke mechanical diesels which can run backwards by design, but these are typically in older agricultural tractors and similar equipment.
How does running backwards happen?
There are a couple of ways to start a diesel engine in reverse, likely one of the easiest being stalling one out in such a way that momentum causes it to restart backwards. Think of something like a bulldozer being overloaded, or a car being parked in gear on a hill. If something was to roll back in such a situation; because everything is still connected to the crankshaft, it would force the crankshaft to go in the opposite direction, which may start it up like a manual transmission car being bump-started, just facing the wrong direction.
The principle behind why it happens relates to how an engine turns over. A full rotation of the piston involves it reaching the apex of its travel, called top-dead center, and firing. This shoves the piston back down, ideally in the correct direction. However, if pre-ignition occurs, it could potentially fire the piston before it's reached top-dead center, meaning it gets fired backwards instead. If the piston didn't travel far enough up, then it won't have the momentum to overcome the ignition process trying to push it back down. This, of course, relies on some sort of engine malfunction, as opposed to intentionally wiring the ignition coil in reverse, which can lead to an engine running backwards as well.
This accidental misfiring is prevalent enough that a specialized mechanism exists which prevents diesel engines from unintentionally running in reverse, due to stalling out and restarting running backwards. Overall, though, it's quite a rare phenomenon: No serious publications reported on engines running backwards, apart from hearsay, modifications, and the occasional accidental event in older mechanical diesels.
The hypothetical consequences
Two-stroke engines have it far easier than four-stroke engines because of the way oil lubricates each of these. A two-stroke engine uses a fuel/oil mix, whereas a four-stroke uses a separate oil tank that draws oil with a pump. A gear-driven oil pump is designed to operate one way, so if one were to run a four-stroke diesel engine backwards, the oil pump wouldn't be able to pick up anything and you would have effectively zero oil pressure as a result. Running an engine with no oil pressure can be disastrous because that's all metal-on-metal contact.
The most fundamental concern for a two-stroke running backwards isn't the oil, of course, but rather that the intake and exhaust are swapped. That still applies to four-strokes, naturally — an engine running backwards will expel its exhaust out of the intake in a plume of smoke because there's no particulate filters or catalytic converters up there. But in either engine configuration's case, it could potentially damage or clog up intake components such as filters and turbo elements, and whatever else is in the way.
If your own engine somehow manages to reverse itself, either from stalling out, bad wiring, bad engine timing, and so on, then the ignition should work all the same. All engines, no matter which direction they're running in, require fuel to operate. Because diesel engines shut off by physically interrupting the fuel supply (since there's no spark plug to turn off), simply turning the engine off and back on should fix the issue, provided it's not a systemic problem with the engine's configuration.