After a little tinkering, I managed to create this self-locking differential. It locks when the car goes straight and unlocks when turning:
A set of 12t gears are connected to the steering rack. When the rack is in the middle (and the car going straight), the two halfshafts are coupled together, locking the differential. When the rack moves to the left or right to steer the car, the 12t gears disengage with the 20t gears and let the differential act like an open diff:
The main downsides I see with this setup are that the differential may stay locked during wide turns with small rack movement and the width of the axle is increased. A standard independent suspension with a differential and 68.8x36 ZR wheels (the combination I usually use) is 25 studs wide; with this feature it increases to 27.