Is there any reason why a dog was chosen as Yudhishtira's. Is it mentioned in the Mahabharata?
Yes Yudhishthira accompanied by a dog-during the ending stages of his life , While approaching swarga. It was Dharma (Yama) himself who was in the form of dog appeared before Pandavas to test them. The account is mentioned in Book 17 Chapter 3 - Mahaprasthanika Parva, Mahabharata .
The dog accompanied the Pandavas during their last days was actually supreme lord in the form of Yama , Who tested Yudhisthira in his last moment during he was ascending to swarga. So the lord took this form of a dog to test Yudhishthira.
निक्षिप्य मानुषं देहं गतास ते भरतर्षभ |
अनेन तवं शरीरेण सवर्गं गन्ता न संशयः||
nikṣipya mānuṣaṃ dehaṃ gatās te bharatarṣabha
anena tvaṃ śarīreṇa svargaṃ gantā na saṃśayaḥ
Shakra said, ‘Immortality and a condition equal to mine, O king, prosperity extending in all directions, and high success, and all the felicities of Heaven, thou hast won today. Do thou cast off this dog. In this there will be no cruelty
भक्त तयागं पराहुर अत्यन्तपापं; तुल्यं लॊके बरह्म वध्या कृतेन |
तस्मान नाहं जातु कथं चनाद्य; तयक्ष्याम्य एनं सवसुखार्थी महेन्द्र | |
bhakta tyāgaṃ prāhur atyantapāpaṃ; tulyaṃ loke brahma vadhyā kṛtena
tasmān nāhaṃ jātu kathaṃ canādya; tyakṣyāmy enaṃ svasukhārthī mahendra
"Yudhishthira said, ‘It has been said that the abandonment of one that is devoted is infinitely sinful. It is equal to the sin that one incurs by slaying a Brahmana. Hence, O great Indra, I shall not abandon this dog today from desire of my happiness. Even this is my vow steadily pursued, that I never give up a person that is terrified, nor one that is devoted to me, nor one that seeks my protection, saying that he is destitute, nor one that is afflicted, nor one that has come to me, nor one that is weak in protecting oneself, nor one that is solicitous of life. I shall never give up such a one till my own life is at an end.’
The answer is in this shloka
तद धर्मराजस्य वचॊ निशम्य; धर्मस्वरूपी भगवान उवाच |
युधिष्ठिरं परति युक्तॊ नरेन्द्रं; शलक्ष्णैर वाक्यैः संस्तव संप्रयुक्तैः ||
tad dharmarājasya vaco niśamya; dharmasvarūpī bhagavān uvāca
yudhiṣṭhiraṃ prati yukto narendraṃ; ślakṣṇair vākyaiḥ saṃstava
Vaishampayana continued: "Hearing these words of king Yudhishthira the just, (the dog became transformed into) the deity of Righteousness, who, well pleased, said these words unto him in a sweet voice fraught with praise.
And why Dharma took the form of Dog is mentioned in Shlokas 19, 20 and 21. It is told by dharma himself that in the past he once formerly examined Yudhishthira in the Dwaita Forest. That time also Yudhisthira without prejudice, revived Nakula instead of Bhima and Arjuna. at that time also Yudhisthira abandoned Indra's chariot by saying "This Dog is My Devotee , I will not desert him.
So same event got repeated and Dharma took same form of Dog as he took previously.
पुरा दवैतवने चासि मया पुत्र परीक्षितः
पानीयार्थे पराक्रान्ता यत्र ते भरातरॊ हताः 19
भीमार्जुनौ परित्यज्य यत्र तवं भरातराव उभौ
मात्रॊः साम्यम अभीप्सन वै नकुलं जीवम इच्छसि
"Dharma said: ‘Thou art well born, O king of kings, and possessed of the intelligence and the good conduct of Pandu. Thou hast compassion for all creatures, O Bharata, of which this is a bright example. Formerly, O son, thou wert once examined by me in the woods of Dwaita, where thy brothers of great prowess met with (an appearance of) death. Disregarding both thy brothers Bhima and Arjuna, thou didst wish for the revival of Nakula from thy desire of doing good to thy (step-) mother. On the present occasion, thinking the dog to be devoted to thee, thou hast renounced the very car of the celestials instead of renouncing him. Hence. O king, there is no one in Heaven that is equal to thee. Hence, O Bharata, regions of inexhaustible felicity are thine. Thou hast won them, O chief of the Bharatas, and thine is a celestial and high goal.’"
And the explanation is in the former test Yudhisthira said that he doesn't want to leave his near and dear ones and the dog was there i.e.he was near to Yudhisthira at previous time. So to test the righteousness and sticking to his words ,Dharma again took the form of dog to see the dog is still near and dear to Yudhisthira. See Page 23 -24