There is no rule that will tell you when to use which reading. There are general guidelines, like "on readings in compounds", but there are also plenty of exceptions, including words which are a mix of kun/on readings and words which aren't read using either kun or on.
The "why" is historical - remember that kanji were imported from China over a period of time, and applied to existing words, which is why there are loads of readings for some kanji and lots of exceptions.
The only thing to do is to learn the vocabulary, particularly for those exceptional cases. There are kanji which have only one reading, or which have lots of readings but only one or two which are common in compounds. As your vocabulary increases you'll get better at making educated guesses about the reading of compounds you don't know.
Numbers & counting is an area which you're probably better off learning from some sort of textbook about counters.
(If you want to type in Japanese, you need some sort of IME - what operating system do you have?)