Simmer the chicken, 1/2 of the onions, and the garlic in water to cover until the chicken is done and starts to fall away from the bones. Remove the chicken. Strain the broth and reserve.
Remove the meat from the bones and chop the chicken along with the remaining onion. Combine with the chiles and sour cream. Place the mixture in a casserole dish.
Bring the reserved broth to a boil and gradually add the masa while stirring constantly. Reduce the heat and cook until the mixture thickens, about 10 minutes. Remove from the heat and stir in the egg yolks. Spread this batter over the casserole and top with the grated cheese.