Olympiakos striker Castillo broke the deadlock after 21 minutes with a sublime effort.
He received Juan Carlos Cach's chip inside the area before flicking the ball over Brazil defender Juan and, without letting the ball touch the ground, slotted the ball past goalkeeper Doni.
Morales doubled Mexico's lead eight minutes later after curling a superb free-kick that floated over the wall and went past the motionless Doni.
Brazil pushed forward in the second-half but were denied on several occasions by Mexico's brilliant goalie Guillermo Ochoa.
The Selecao came close in the 71st minute when Robinho's powerful shot was denied by the crossbar as they were unable to hand Dunga a victory in his first official match in charge.
In the Group B game, Chile scored two late goals to grab a 3-2 victory over Ecuador.
Wigan midfielder Antonio Valencia put Ecuador ahead in the 16th minute but was cancelled out by Humberto Suazo's strike five minutes later.
Just two minutes later, Cristian Benitez restored Ecuador's lead but they were denied again by Suazo ten minutes from time.
Substitute Carlos Villanueva notched what proved to be the winner three minutes before the final whistle.