Batman learned of their weaknesses by being on missions with them for years and seeing them react to whatever stimuli is needed to trigger that weakness. He's not called the World's Greatest Detective for nothing.
Let's ask how often knowing the strengths and weaknesses comes in handy fighting against your enemies - The White Martians for instance - each with the physical capacity to stand toe to toe with Superman...
In most iterations of the Justice League he is the tactical leader on the ground because of his encyclopedic knowledge of the JLA's enemies. The Martian Manhunter (if he's available) relays his commands to members mentally when necessary.
As a team lead, he has to have an intimate knowledge of each member's capacity (as much as they are comfortable relaying to him). Despite their reluctance, Batman will likely watch a member and learn about them by watching them in action. Given how often the JLA talked about their abilities it wasn't hard to learn if you were paying attention.
Batman considers himself (and perhaps Wonder Woman) the members most likely to "do whatever it takes" to stop a renegade member of the JLA before they can harm innocents. So all of his contingencies are designed to be delivered by him exclusively.
Being a contingency minded individual, and only Human it occurred to him, before anyone else that the members of the League might need to be stopped if under alien influences. In the DC Universe, mind control is REAL. See: Maxwell Lord and Eclipso.
- He likely also steals and compares caches of information from military and governments who have their own security files on metahumans as well for exactly the same purposes. See: Department of Extranormal Operations.
Being a Human among gods kept Batman attentive and analytical. If a heroes arch-enemy can exploit a weakness, so can he. Those weaknesses include:
- Superman: It's Kryptonite, certain radiations and magick.
- Aquaman: it's dehydration.
- Green Lantern: It's concentration, fear and occasionally the color yellow.
- Martian Manhunter: It's fire. Psychosomatic or otherwise, he becomes unable to fight in the presence thereof.
- Wonder Woman: its psychological. Physically she has no serious weaknesses that are easy to exploit so he screws with her basically human mental state and has her fight in her imagination to exhaustion.
- The Flash: It's his attention span. He is basically Human if you can catch him off-guard.
Batman has been watching the League for years, as a member. With performance reviewing of missions, mission reports, teamwork analysis, I suspect most of the League can do the same thing in their heads, if they had to. Batman was the only person to codify it and make a protocol for every member, up to and including actual (untested) materials for each contingency.
For anyone truly aware of his mental predisposition they should have realized he would have been doing this. And perhaps encouraging it.
If I had to pick one reason it was prudent to learn the weaknesses of the JLA it was the threat of T.O. Morrow's most terrible technology: Amazo. Able to imitate the powers of any member of the JLA (and their corresponding weaknesses) it behooved one to stay caught up on what everyone could do, just in case you were facing Amazo...
Superman realized it was necessary when he gave Batman a shard of Kryptonite. Just in case. Batman went the extra mile and made contingencies for all of the League.