Javert reveals his reasons in the song he sings when he commits suicide.
And must I now begin to doubt, who never doubted all these years/ My heart is stone and still it trembles/ The world I have known is lost in shadows/ Is he from Heaven or from Hell?/ And does he know, that granting me my life today, this man has killed me even so...
I am reaching but I fall and the stars are black and cold/ As I stare it to the void/ to a world that cannot hold
I'll escape now from that world, from the world of Jean Valjean/ There is nowhere I can turn/ There is no way to go on.
Javert kills himself because the mercy shown to him by Jean Valjean so disrupts his black and white world view that he cannot bear to live in a world he no longer understands.
One of the key themes in the work is that those who cannot adapt are destroyed (Javert, Fantine, Enjolras), while those who are flexible thrive (Thénardier). It is really a very cynical work when you get down to it.