How does the nose wheel lock on the Robin DR400 work?
It looks like the "How do they work?" question has already been addressed pretty well, so I'll answer some of the other parts of the question:


  What is gained by having the nose wheel lock itself?



The nose gear is prevented from turning during flight when the rudder pedals are actuated. If the nose gear turned when the rudder was being used in flight, it would add a lot of form drag.
The nose gear remains straight until it touches down on landing, which prevents it from landing sideways in a crosswind landing where the rudder is being used to maintain runway alignment. This allows the pilot to continue to use the rudder inputs to maintain the centerline through the landing roll without damaging the tires or having a sudden yaw in the direction that the tire is pointing when the nose wheel touches down.



  Rather than for instance a spring-like mechanism that just keep the wheel aligned with the plane when the plane is in the air.


You mean like a Cessna-style spring linkage, where there is not a hard linkage between the rudder pedals and the nose gear? One advantage of not using the Cessna-style springs is that it's easier to taxi with direct linkages rather than spring linkages. Cessnas have a lag between rudder pedal input and the nose wheel actually turning because of the spring linkages, so you have to give directional inputs ahead of when you actually want to turn. With direct linkages, the nose wheel turns immediately when you push the pedals, which makes taxiing a little easier, especially when you're first learning.


  Are there planes with a different mechanism to keep the nose wheel from moving in flight?


Yes. See above for Cessnas. Also, in larger aircraft (e.g. passenger jets and similar,) there are no mechanical linkages to the nose wheel at all and the nose wheel is turned (mostly) by a separate control from the rudder. This control is called a tiller and it's moved by hand instead of by foot. It looks like this: