To sit on the fence is to be undecided between two options. Wikipedia adds an implied motivation:
… inability to decide due to lack of courage. This is done either to remain on good terms with both sides, or due to apathy regarding the situation and not wanting to choose a position with which one doesn’t actually agree. As a result, someone who “sits on the fence” will maintain a neutral and non-committal view regarding any of the other parties involved.
I didn’t find many sites suggestingan origin.
Superbeefy listed an amusing story that combines the phrase with an American hero and a wise slave:
During the Revolutionary War, a prominent New Jersey jurist, Judge Imlay, hadn’t yet committed to either the revolutionaries or the loyalists. So when Washington encountered one of Imlay’s slaves he asked him which way the judge was leaning.
Washington was so amused by the response that he retold it enough times for it to become part of our language. He said, “Until my master knows which is the strongest group, he’s staying on the fence.”
The site offers no citation, but I like the story.