That's pretty easy: you cross the border, the border guard sees recent stamp showing you traveled to r---ia and you don't fit the profile of someone having a family there, which trip the alarm to look into you slightly more than usual (in normal days the only thing border guards do is check that passport is not forged).
Then the obvious question to "where you exactly you have been there and what for" will come out unexpectedly for you and you will start making up a bullshit story on the spot (after being on the road for the last whole day) and spit out enough signals to look into you even more.
At this point you are taken to a room for a talk and asked to show pictures in your phone, hotel confirmations, train tickets, etc, which obviously show you have been where you are not supposed to and you lying as well. If you panic and refuse to show the phone contents, you are likely just barred from entrance on the spot and put on a list. If you do show the phone contents and there isn't anything noteworthy, but your story is not coherent enough (or the opposite: coherent enough to the point you prepared for it), you get at date with a three letter agency who is supposed to not rely on feelings.
The "how do they know" is always a bad idea as long as people need to know and your actions leave extensive digital papertrail.
That's ridiculously stretched. Russia is huge. Plenty of choice of "where you've been to". And you absolutely don't have to answer anything about where you've been to in Russia, because it's actually not their fucking business. Worst they can do is not let you into Ukraine. Surely, theoretically they can illegally arrest you, and torture you, and whatever, but doing that to a USA citizen (or whoever you are) on a basis of slight suspicion you could've been in Crimea or some other territory they consider theirs inside of Russia, well, that's risking way more than you do.
Then the obvious question to "where you exactly you have been there and what for" will come out unexpectedly for you and you will start making up a bullshit story on the spot (after being on the road for the last whole day) and spit out enough signals to look into you even more.
At this point you are taken to a room for a talk and asked to show pictures in your phone, hotel confirmations, train tickets, etc, which obviously show you have been where you are not supposed to and you lying as well. If you panic and refuse to show the phone contents, you are likely just barred from entrance on the spot and put on a list. If you do show the phone contents and there isn't anything noteworthy, but your story is not coherent enough (or the opposite: coherent enough to the point you prepared for it), you get at date with a three letter agency who is supposed to not rely on feelings.
The "how do they know" is always a bad idea as long as people need to know and your actions leave extensive digital papertrail.