how does it not immediately start spinning?
Physics, and engineering. But I guess that you would like a bit more detail, so let's try dive in.
They tend to have a stabilizing effect by shifting some of the weight on the front wheel and allowing the pilots to control the aircraft with more effectiveness.
These are automatically controlled by the Fly-by-Wire system, so if required they would be retracted.
If they are functioning properly, the resulting force will go through the vertical plane containing the C.o.G. (but a bit below it), so they do not pose much of a problem.
Another thing you have not mentioned, but I am going to add, is crabbed landings (such as this one), since in these situations the aircraft DO tend to spin a little.
In these cases, in the timeframe between touchdown and braking, 2 things help the aircraft remain on the runway: the vertical tail (with the rudder), and the position of the main landing gear w.r.t. the center of gravity of the aircraft. As it can be seen in this image taken from the lecture notes of the course I followed (the title translates to "Braking run in crabbed landing"), normal tricycle gear aircraft tend to be stabilized by their own landing gear in this situation, while the same cannot be said for old school taildraggers.
So, what really could cause a problem? The answer is wind gusts (especially if the wind is perpendicular to the runway), uneven conditions of the runway (say, a puddle or a thin layer of ice on one side of the runway will cause one set of main gear to have less grip than its counterpart on the other side, causing a yawing towards the side with more grip), asymmetrical failures in the thrust reversers, excessive braking while also turning the aircraft to realign to the centerline (particularly a problem if the distance between the two main gears is not sufficient).
How does the aircraft remain on the runway despite these possible problems? At high speeds, thanks to the vertical tail; and at low speeds thanks to the front nose gear. At in-between speeds, the situation is slightly more complicated: the tail is not much useful anymore, while the front gear would risk breaking if used to correct too much. So, for example, a FbW system can help through the asymmetrical use of spoilers.
An example of what could happen, but seen during a take-off, is illustrated in this video (video kindly provided by MichaelK in chat).