Short answer: have the author/GM deliberately design the world so that the threat isn't a serious one.
The devil is in the details.
There are essentially three broad categories of safeguard available, the effectiveness of which vary heavily depending on exactly how your world is set up. Unless you tweak the parameters very carefully, they're all likely to have fairly major implications for what your world ends up looking like.
For a lot of standard Sci-Fi worlds - ones with widespread public ownership of starships, FTL travel using highly efficient engines, effective energy shields, and significant technological capabilities available on the black market - the answer essentially boils down to "you can't". An incoming ship is too fast and too durable to stop in time, and the government doesn't have the ability to prevent a psychopath from taking full control of a ship in the first place.
1) Preventing psychopaths from gaining control of the ship in the first place.
There are two halves to this, which would almost certainly be used in concert.
First is making sure that they never get behind the helm of the ships at all. Starship pilot licenses could be heavily regulated, including mandatory psychological testing (probably at regular intervals). Similarly, the ownership and sale of all starships could be regulated, with all spacecraft either directly government-owned, or owned by people who have been thoroughly checked out and determined not to be a threat to public safety.
Second is making sure that if a sick bastard does manage to get ahold of a ship, they can't crash it into anything valuable. Biometric scanners that only unlock the controls for authorized users are one possible tool. Other options are hard-wired safety systems that won't allow the ship to travel above a certain speed within a certain distance from planets, and remote overrides to allow traffic control to take command of any ship that enters their sphere of control. The effectiveness of these is strongly dependant on how good computer/electronic security is in your world - if criminals have the skills and resources to effectively hack and/or hotwire such systems, then other precautions will be necessary.
2) Intercepting the ship short of its target
This one depends heavily on the performance characteristics of your ships and sensor networks. A successful response requires both that the defenders detect the incoming ship early enough to respond, and that they have assets in place that can intercept the ship once they do detect it. Orbital defense platforms are an option but might find it difficult to prevent debris showers from hitting the planet even if they destroy the ship. More likely this would need warships held on permanent alert (if the threat is serious enough, specially-designed interceptors would probably make up a significant fraction of the world's military forces).
Long-range, high-resolution sensor equipment is essential here, and faster-than-light sensor capabilities are highly recommended. In particular, a ship traveling at close to or above light-speed is effectively impossible to intercept without FTL sensors - your first 'warning' arrives at the same time as the incoming ship.
Effective long-range weaponry helps the defenders - without it, they need an actual physical interception with another ship, and that could be difficult. Effective ship defenses help the attacker, as does any mechanism (artificial gravity, force fields, inertial sumps...) that will prevent a ship from being physically deflected from its course by an outside force.
High maximum speeds are more useful for the attacker: they increase damage potential, decrease the time the defenders have available to respond and make the ship a more difficult target to intercept.
High ship acceleration rates favour the defender - or rather, low accelerations favour the attacker (as long as ship operation ranges are significantly higher than maximum sensor ranges). The attacker can spend as long as they like accelerating, while the defenders are scrambling to intercept a ship that is likely already at full speed.
3) Ensuring that there aren't any targets
If neither of the above is feasible, the only remaining option is to ensure that there's nothing available that a suicide run can destroy. Burying everything below the surface of the planet is one option, but only works against relatively slow starships - at sufficiently high speeds, you just can't bury things deep enough.
Otherwise, the remaining option is to abandon planets completely. Move everything vital onto self-propelled space stations, and keep them moving in a random pattern to prevent an attacker from being able to predict where they'll be accurately enough to hit them.