Most people's immune systems function well at any age.
While the immune system does change over a lifespan, it's generally robust enough at all ages to handle typical threats. According to experts, the risk for infection and illness isn't significantly higher than normal for most people, regardless of their age. It's also important to note that maintaining good health habits can positively impact immunity at any stage of life.
In essence, there isn't a single "best" age for immunity; rather, immunity is generally strong throughout life and can be further supported by healthy practices.