No, horses in the Olympics do not have to be of the same nationality as their riders.
While riders represent their own countries, horses are considered athletes in their own right. A horse from any country can compete as long as it meets eligibility criteria set by the International Olympic Committee and the FEI, including registration with a recognized breed registry, suitable age and temperament, good health, and Olympic-level qualification.
It is common to see horses from various countries competing alongside riders from different nations.