I travelled on the Prague–Moscow train in 2015. I had a transit visa for Belarus and a tourism visa for a fortnight-long stay in Russia. My tour actually left the Prague–Moscow train in Brest (the first station in Belarus where passport formalities and the bogie exchange to accomodate for Russian broad gauge occur) when we arrived in the morning, had a tour of the city and boarded an evening train (Brest–Moscow) on to Moscow.
Belarus and Russia form a union known as the Union State, including freedom of movement for both countries’ citizens and a customs union. From the point of view of an international traveller, this means there are no inspections when crossing the border between the two states. Your passport and visa will be checked in Brest once you cross the border into Belarus. You will be handed a Russian migration card to fill out and always keep with your passport. The entry stamp will probably be placed on your Belarusian visa with your Russian visa remaining unstamped. There’ll probably also be a quick customs check which I recall to be a guy walking through with a torch and checking for any obviously hidden stuff.
In terms of how it will all happen: unless they severely changed procedures the immigration checks will be the very first thing on Belarusian soil in a stationary train after you crossed the bridge from Poland. The train will then roll into the ‘Polish side’ of Brest station and passengers wishing to disembark will disembark. It will then be pulled back and pushed into the hall where bogies (and couplers) are exchanged which is quite a spectacle that is worth watching from the windows if you are not allowed to exit. Finally, it gets pulled out of the hall into the other direction and reaches the ‘Russian side’ of Brest station where onward passengers may board before departing towards Moscow.
When continuing on towards Moscow, you will be allowed a proper night’s sleep (or a full day of enjoyment) and likely won’t notice the border as you drive across it. I certainly wasn’t awoken but woke up the next morning in the outskirts of Moscow. You will already have been handed the necessary migration card in Brest; no further formalities are required. Specifically, you do not have to arrange for any customs inspection in Moscow since that has been performed in Brest.
After two weeks of crossing Russia by train and back, I exited on the Allegro to Helsinki from St. Petersburg. There, immigration inspection is performed on the running train right after its departure from St. Petersburg Finlandski station. My Russian visa received a Russian exit stamp, the migration card was taken away and everything was fine. There was also exit customs inspection by a Russian agent but that consisted only of a number of short questions which I could all answer to his satisfaction.
There were some rumours and reports of difficulties from the Russian side in recent years (post 2017) after Belarus introduced a visa-free entry scheme for a number of nationals through Minsk National Airport. Apparantly, so I heard and read, Russia was unhappy with tourists entering Belarus visa-free and continuing on by train to Russia although I never saw a full formal explanation. I was concerned whether this affected rail travellers, too. However, the all-knowing Man in Seat 61 confirms:
No problems have been reported by any westerners using the direct Russian Railways trains from Paris, Nice, Vienna, Berlin, Prague or Warsaw to Moscow via Belarus in 2017, 2018 or 2019, in spite of what you may have read elsewhere online.
As long as you have a Russian visa and a Belarus transit visa, travel from Western or Central Europe to Moscow on a direct Russian Railways international train seems fine, even if it crosses Belarus. The problem only arises if you want to START a train journey in Belarus to travel to Russia.
Thus, you should have no problems on your trip.