Did Rama or Krishna ever practise meditation?
Not sure if he did it regularly, but on the night before Arjuna slayed Jayadratha, Krishna went into a state of yoga and meditation:
"Sanjaya said, 'Then lord Kesava, of eyes like lotus-petals, having entered the unrivalled mansion of Arjuna, touched water, and spread (for Arjuna) on the auspicious and even floor an excellent bed of Kusa blades that were of the hue of the lapis lazuli. And keeping excellent weapons around that bed, he adorned it duly with garlands of flowers and fried paddy, perfumes and other auspicious articles. And after Partha (also) had touched water, meek and submissive attendants brought the usual nightly sacrifice to the Three-eyed (Mahadeva). Then Partha, with a cheerful soul, having smeared Madhava with perfumes and adorned with floral garlands, presented unto Mahadeva the nightly offering.
Then Govinda, with a faint smile, addressed Partha, saying, 'Blessed be thou, O Partha, lay thyself down, I leave thee.' Placing door-keepers then, and also sentinels well-armed, blessed Kesava, followed by (his charioteer) Daruka, repaired to his own tent.
He then laid himself down on his white bed, and thought of diverse measures to be adopted. And the illustrious one (Kesava) of eyes like lotus petals, began for Partha's sake, to think of various means that would dispel (Partha's) grief and anxiety and enhance his prowess and splendour.
Of soul wrapt in yoga, that Supreme Lord of all, viz., Vishnu of wide-spread fame, who always did what was agreeable to Jishnu, desirous of benefiting (Arjuna), lapsed into yoga, and meditation.
There was none in the Pandava camp who slept that night.
What happens next is really interesting. Arjuna, despite his anxiety, falls asleep in his tent and Krishna takes Arjuna (in Arjuna's dream) to Shiva's abode to seek his blessings:
Endued with great energy, his body seemed to be flaming with a thousand eyes. And he was seated with Parvati and many creatures of brilliant forms (around him). And his attendants were engaged in singing and playing upon musical instruments, in laughing and dancing, in moving and stretching their hands, and In uttering loud shouts.
... And Krishna and Arjuna said, 'We bow to Bhava, to Sarva, to Rudra, to the boon-giving deity. We bow to the lord of all creatures endued with life, to the god who is always fierce, to him who is called Kapardin! We bow to Mahadeva, to Bhima, to the Three-eyed, to him who is peace and contentment. We bow to Isana, to him who is the destroyer of (Daksha's) sacrifice. Let salutations be to the slayer of Andhaka, to the father of Kumara, to him who is of blue throat, to him who is the creator.'
Arjuna gets the indication that his vow (of slaying Jayadratha) will be soon accomplished:
... And the god also granted him the terrible Pasupata weapon and the accomplishment of his vow. Then having thus once more obtained the Pasupata weapon from the supreme god, the invincible Arjuna, with hair standing on end, regarded his business to be already achieved. Then Arjuna and Krishna filled with joy, paid their adorations unto the great god by bowing their heads. And permitted by Bhava both Arjuna and Kesava, those two heroes, almost immediately came back to their own camp, filled with transports of delight. Indeed, their joy was as great as that of Indra and Vishnu when those two gods, desirous of slaying Jambha, obtained the permission of Bhava that slayer of great Asuras.'"
And towards the end of Mahabharata, before deciding to give up his body too, Krishna was apparently in a state of yoga:
Conversant with the truth of every topic, Vasudeva, though he was the Supreme Deity, wished to die, for dispelling all doubts and establishing a certainty of results (in the matter of human existence), simply for upholding the three worlds and for making the words of Atri’s son true. Having restrained all his senses, speech, and mind, Krishna laid himself down in high Yoga.
When Krishna goes to Hastinapura as an emissary and stays at Vidura's place, he also sets other examples like how should one start the day:
And rising from bed, Janardana of Dasarha's race, that bull amongst all the Sattwatas, went through all the customary acts of the morning. And having cleansed himself by a bath, recited the sacred Mantras and poured libations of clarified butter on the sacrificial fire. Madhava decked his person and began to worship the rising sun. And while the unvanquished Krishna of Dasarha's race was still engaged in his morning devotions, Duryodhana and Suvala's son Sakuni came to him and said, 'Dhritarashtra is seated in his court, with all the Kurus headed by Bhishma and with all the kings of the earth. They are all soliciting thy presence, O Govinda...
Rama also sincerely meditated on Lord Narayana the day before his coronation ceremony:
After Vasistha left, Rama took bath and meditated on Lord Narayana with undistracted mind along with his wide-eyed wife, Seetha. [2-6-1]
Taking the vessel with clarified butter on his head as per scriptures, he offered to Lord Vishnu the clarified butter, by dropping it into the blazing fire. [2-6-2]
Rama ate the remainder of clarified butter after finishing the sacrifice, which he performed for his own good, silently meditated on Lord Narayana with controlled mind and slept along with Seetha on a properly laid bed of Kusa grass in a splendid temple of Lord Vishnu. [2-6-3, 2-6-4]
Note: “The question: Did Rama or Krishna ever practise meditation?” is licensed by Stack Exchange Inc (https://hinduism.stackexchange.com/); user contributions licensed under CC BY-SA.