Yes, it is okay to wear shorts in Mexico City. However, depending on the time of the year it can be chilly or even cold in the evenings, and pants might be more comfortable. Shorts are not commonly worn by the locals, though they are slightly more common for men.
Locals are more often found wearing long pants, skirts, or dresses that enable them to remain comfortable even when temperatures drop slightly in the evenings.