Although this is an issue of quantum chemistry rather than pure organic chemistry alone, let’s try to make it simple.
1). Roughly, the various tautomers may not be equal, regarding their energy content, as well as their contribution in the tautomerism.
2). The same happens to the various aromatic forms that might not be equal, regarding their energy content, as well as their contribution in the overall aromatic hybridism (especially, in fused aromatic rings).
3). In this case, both products are aromatic but the top product has three endocyclic double bonds in the pyrimidine ring and two endocyclic double bonds in the pyrazole ring and therefore, it has a slightly lower energy content than the bottom form, which has two endocyclic double bonds and two exocyclic double bonds in the pyrimidine ring, together with two endocyclic double bonds in the pyrazole ring.
4). As a consequence, the top product can easily be obtained by kinetic control (e.g. lower temperatures, shorter reaction times), in contrast to the bottom product that can only be obtained by thermodynamic control (e.g. reflux, longer reaction times), even without Lewis catalysis.