Hot water only
The water heater. Either the anode rod has been consumed and the tank lining is now corroding, or sediment is being stirred up.
An anode rod check is cheap and can add years to a tank. A tank already rusting through cannot be saved.
Cold water only
Galvanized supply pipe, or the municipal main. If the whole street has it after hydrant flushing, it clears within hours.
If it is only your house and it appears on first draw each morning, your own galvanized pipe is shedding rust. That is a repipe conversation.
Both hot and cold
The service line or the main. Iron or manganese in a well supply produces the same effect and needs filtration rather than plumbing repair.
Is it safe?
Rust is not a health hazard at the concentrations that discolor water, but it stains laundry and fixtures and it tells you a pipe is deteriorating.
Sudden discoloration with a change in taste or smell is worth reporting to your water authority as well.