"mayn't" means "may not" (dialect or old-fashioned). The negative is used in an idiomatic way, and its logic is a bit hard to explain, since the meaning is really the same as "It never knows when it may be driven into something irrational and unjust".
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.