Makeup has an expiration date which you should follow to make sure you're only using products that are completely safe to use. Here's a quick, general guideline for when you should toss old makeup and get replacing!
With liquid foundation, the consistency can thicken due to oil rising to the surface over time. Another problem it faces a higher chance of bacteria growth because we're constantly putting our hands in the product, leading to things like breakouts and irritation to the skin.
Powder based foundation doesn't face the same issues because there's no water for bacteria to grow on, although certain ingredients become harder to blend over time and begin to break down.
Liquid foundation - 6 months
Powder foundation - 2 years