First, the word doesn't derive from the type of sand bags we're all familiar with. It's not the defensive sand bags - those used for flood control, lining foxholes, and so on - but the offensive sand bags that give us the word "sandbagger."
Gangs and street toughs of the 19th century used sand bags as a weapon of choice. Take a sock or small bag, fill it with sand, wrap it tightly, and wail away on someone (well, don't actually wail away on someone, but imagine that you are) and you'll see how effective a weapon a small sand bag can be.
Gang members used such weapons to intimidate their foes or average citizens. To threaten and bully the populace.
This definition of sandbagger - a person who uses a sand bag as a weapon - can still be found in many dictionaries; it's the first definition for the word in most older dictionaries.
But the word didn't go directly from its gangland origins into golf; there was an intermediary step in its adoption by the sports world, and golf, to mean someone who misrepresents his ability to gain an advantage.
According to the website Word-Detective.com, that intermediary step was poker.
Say you're in a poker match and you're dealt a fantastic hand. If you place a huge bet right off the bat, you might scare most of your poker mates into folding. Instead, you might choose to bet small amounts, hoping to keep your opponents in the match, increasing the pot, up until the moment you show your cards.
As Word-Detective.com puts it, the poker meaning "... described a player who held off raising the stakes in order to lull the other players into a false sense of security. The poker sandbagger would pounce late in the game, clobbering the other players with his good hand."
The poker player, in other words, misled his opponents about how good his hand was ... until it was time to whip out the "sand bag" and beat those same opponents with it.
And that's how "sandbagger" came to have its golf meaning.