Can I meditate or do japa lying in bed before sleep?

yes, mental japa in bed is a lovely way to fall asleep, but keep your main practice for a seated time.

Many saints encouraged falling asleep with the name of God, so that the last thought of the day is a good one. Lying in bed and repeating “Rāma”, “Kṛṣṇa”, “Om Namaḥ Śivāya” or your own mantra mentally, without a mālā, is widely practised and very calming, especially for people who struggle with worry at night.

The limitation is simple: lying down signals the body to sleep, so deep, alert meditation is hard in that position. That is why formal sādhanā is done sitting, with the spine upright.

So use both: a seated practice at your regular time, and gentle name-remembrance in bed. If you are unwell, elderly or bedridden, lying-down japa is fully valid worship — the tradition never asks the body to do what it cannot.

Source: bhakti saints’ teaching on nāma-smaraṇa

Dharma Q&A — worship at home · Ask a Jyotishi your own question