A little story...
Oh, you could probably get a handgun over to Iraq or Afghanistan without much problem...but when are you going to be able to carry it after you get there? Your soldiers will know about it and people will talk. Eventually, word will get to somebody who outranks you and does NOT approve.
For example, when I got back to Baghdad after two weeks of leave I found that my company commander had ordered a bunch of Knight's accessory rail handguards for our M16A4 rifles. And everyone had installed theirs already. Having been gone, my rifle did not have the handguards.
Frankly, I didn't want them. They made the rifle heavier, as they were machined alloy. And ruined the balance of the rifle, making it muzzle-heavy. More importantly, we didn't have any "gadgets" in our inventory to even put on these rails. If I were to suddenly come into an ACOG or red dot sight, I would've mounted it to the A4 flattop rail, not the handguards.
The only thing we had was a forward pistol grip to add to the handguards. Being a competitive shooter, I found the foreward grip somewhat silly.
So for about two weeks I was walking around with my standard handguards. Until my commander finally noticed my rifle didn't look like everyone else's and ordered me to put mine on. I briefly made the argument that a soldier's rifle should be what HE thinks he needs to fire accurately, not that they all "look" the same.
(You will also encounter this kind of thinking from 1SGs and Sergeants Major who think everyone's ammo pouches and gear on their body armor should be "dress right dress" rather than where the individual soldier prefers them to be for ease of access and speedy reloads)
I made my arguments and was overruled. My rifle had to look like everyone else's. That was more important than whether or not I believed I could fire more accurately with the rifle the way I wanted it.
Be prepared to deal with that mentality in the military.
So, say you've got your non-issue pistol over there and you've managed to keep it, unnoticed and uncommented on. Great.
Now...how do you get it back home? That's the tough part. They go through all of your baggage. They check everything you mail home in boxes.
Frankly, I wouldn't want to consider a $500 pistol a throwaway affair I got 7 months of use out of.