As notednoted, in copious other placescopious other places on Cross Validated, the Mann-Whitney (aka Mann-Whitney-Wilcoxon) rank sum test is inappropriate as a post hoc test following rejection of a Kruskal-Wallis test for two reasons:
The Kruskal-Wallis test statistic is based on shared rankings of all the data, but the Mann-Whitney test is based on rankings only of data for two groups at a time. This means that is a very real sense, the Mann-Whitney is using different data than the Kruskal-Wallis test. Dunn's test uses the same data rankings as the Kruskal-Wallis test. The strictly more powerful than Dunn's test (when used post hoc, following a Kruskal-Wallis rejection) but less widely known Conover-Iman test also uses the same rankings as the Kruskal-Wallis test.
The Mann-Whitney test does not use an estimate of the pooled variance as implied by the Kruskal-Wallis test's null hypothesis. This is analogous to the pooled variance used in post hoc pairwise t tests following the rejection of a one way ANOVA. Dunn's test uses an estimate of the pooled variance, as does the Conover-Iman test.
Dunn's test is based on an asymptotic normality (z distribution) assumption, while the Conover-Iman test is based on an approximately normal (Student's t distribution) assumption, and this is why the Conover-Iman test has more power than Dunn's test.
References
Conover, W. J., & Iman, R. L. (1979). On multiple-comparisons procedures (Technical Report LA-7677-MS). Los Alamos Scientific Laboratory.
Dunn, O. J. (1964). Multiple Comparisons Using Rank Sums. Technometrics, 6(3), 241–252.