You should replace sleeping pillows every one to two years (source).
Pillows absorb a whole lot of stuff throughout the night: sweat, saliva, bacteria… so it’s a good idea to replace them quite often. Another way to test if it’s time for a new pillow is to fold the pillow in half. If it stays that way — it’s time for a new pillow.