Goats can be castrated at almost any age, but 2–4 months is the ideal window for health, welfare, and management reasons:
After 4 months: Still doable, but requires surgical method, anesthesia, longer recovery. Adult bucks castration is major surgery—consult a vet.
Note: If raising for meat, many castrate at 1–2 weeks (banding) for maximum tenderness and ease. Dairy wethers (pets/pack goats) often done at 8–12 weeks.