Oh my dear Joseph, that question can't be answered. Prepositions don't have rules, it depends on the context / word / verb / noun / anything imaginable.
Let's take English for example. Which preposition do you use to express dates?
You say "in March", but when you add a day, it changes to "on March 12".
Also, "at night" but "in the morning".
So just like Rosia said, you have to memorize by heart, there are no special rules.
I have the same problem in English and Italian, you're not alone, don't worry.