We are travelling Berlin–Moscow by train. We have a Belarus transit visa valid from August 18, and a Russian visa valid from August 19. The train enters Belarus in the evening August 18 and arrives at the Russian border in the early hours August 19. So, in theory everything should be fine. The question is: will the border officials in Brest also see it this way, given the fact that they will stamp us in both for Belarus and Russia?
I did a similar trip last month. The border officials in Brest only put an entry stamp on my Belarus visa. I don't recall them even looking at the Russian visa or asking where I was going after transiting Belarus. (Almost all trains stop in Minsk where you can change, even on a transit visa, so it's not a foregone conclusion that you are travelling onwards to Russia, even though I'm sure that's the norm; possibly you could be travelling on to Lithuania, back in the Schengen area.) In addition to stamping my passport, on entry to Belarus, I was given a stamped entry form that you need to keep until your departure from Russia. On leaving Russia, they took this paper, seemed to checked that there was an entry stamp on my Belarus visa, and put an exit stamp on my Russian visa.
Addendum: Are you travelling on train 010Щ «Polonez»? If so although you exit Poland before midnight, the border inspection on entry into Belarus is frequently after midnight, and if so your Russian visa will presumably already be valid.
Belarus border guards do not (at least should not by law) check your visa to any country apart from Belarus. Moreover neither their Russian colleagues do it (apart from Russian visa if needed). So it is only the carrier's (train chief) responsibility to check your visa..
So.. Belarus will check Belarus visa, Russians check the Russian
You need to be sure that your visa is valid when you enter the country that the visa is for. So do not enter Russia before your Russian visa is valid, and do not enter Belarus before your Belarusian visa is valid.
However, the border officials of Belarus in Brest are not supposed to check whether you have a Russian visa at time point X. It is not, and cannot be illegal to enter Belarus without a valid Russian visa. You could, for example, use your transit time to visit Brest and Minsk, spending an additional night at a hotel. You could take a detour across the country for an additional night. All of this would be covered by a transit visa, as long as your transit is reasonably quick (I think you have something like 48 hours to leave the country after entering, but don’t quote me on that). Thus, they should let you in, even if your Russian visa isn’t valid until 20 hours later.
Be aware that they may ask you questions to make sure that your travel plans check out. (They don’t want you to be stopped at any border of Belarus and not let into the neighbouring country.) Be sure to answer truthfully. I have only done the trip once as part of a larger group and was not asked, but my visa were valid for the same period.
If you are on a train that does not cross the border into Russia until after that day’s midnight, they will likely know that, though.