Warning: This answer may contain serious spoilers for those who have not read ADWD. This is not the official position of GRRM but is derived from Canon evidence in favor of this very popular theory.
TL;DR They did not! They did it for a Blackfyre. Aegon is a Blackfyre thus Golden Company is honor bound to answer his call to arms. And no, Aegon and Jon Connington don't know that. Illyrio, Varys & Blackheart Toyne knew that.
Toyne most likely instructed his successor Homeless Harry Strickland in this matter before his demise. Despite being a cautious and somewhat craven man, Strickland could be trusted because his family was with the GC for four generations.
Harry may have later revealed the plan to his officers when the time came and this is why GC officers were aware of who Aegon VI "Targaryen" really was and absolutely willing to obey him.
Blood Contract of Golden Company
"Some contracts are writ in ink, and some in blood. I say no more."
This quote says it all.
Golden Company never broke a contract once during all their years of service. Yet suddenly they break off a profitable contract and refuse many others because a "Targaryen" pretender had called for them.
Golden Company did not care a fig about Targaryens. They spent their whole history fighting against the Targaryens. When Aerys II was killed and his heirs forced into exile, what did GC do? Did they rush to offer their allegiance to Viserys Targaryen? No, they did not. When Viserys invited them to a feast and requested their support, they laughed at him. As Dany recalls:
They ate his food and heard his pleas and laughed at him.
Later they claim that the plan was that Viserys would join GC with Dothraki screamers on his back. Why laugh at someone you mean to take as your king eventually? Why reject his request for aid when your plan is to help him eventually?
This begs the question, Who are the Golden Company bound to in Blood? The answer is, House Blackfyre. Golden Company was founded by exiled Blackfyre loyalists with the sole purpose of one day seating a Blackfyre on the Iron throne and take possession of their own holdings which they had lost in the failed rebellions. Why would they laugh at one undoubtable Targaryen and swear allegiance to another Targaryen whose claim of parenthood are doubtful? Because they know he is not a Targaryen even if he does not know himself.
Even today Golden Company's motto is:
Beneath the gold, Bittersteel.
Which implies that beneath all the gold, Bittersteel is still alive in men of his company and so is his mission. That is the ultimate mission of GC, that is their contract written in blood of many generations who died for House Blackfyre. This is the contract which trumps everything else in the world for them.
Dany's visions about a fake dragon and people cheering for it
Daenerys has seen this in her visions in House of the Undying:
Glowing like sunset, a red sword was raised in the hand of a blue-eyed
king who cast no shadow. A cloth dragon swayed on poles amidst a
Granted a dragon is still a dragon, be it black or red but our little dragon here is pretending to be a different sort of dragon, which makes him no better than a mummer's dragon. The "Mummer's dragon" is how Dany describes it to Jorah the Andal. Oh and fun fact, Varys was a mummer in Myr. Aegon is his dragon. Which makes him a mummer's dragon.
Female Line of House Blackfyre
When confronted by Tyrion, Illyrio gave away more than he would have liked:
Illyrio brushed away the objection as if it were a fly. “Black or red,
a dragon is still a dragon. When Maelys the Monstrous died upon the
Stepstones, it was the end of the male line of House Blackfyre.”
Ok Fine Illyrio, Male Line is dead. Do you mean you know someone descended from female line of House Blackfyre?
Illyrio definitely knows, he married one of them after all.
Illyrio thrust his right hand up his left sleeve and drew out a silver
locket. Inside was a painted likeness of a woman with big blue eyes
and pale golden hair streaked by silver. “Serra. I found her in a
Lysene pillow house and brought her home to warm my bed, but in the
end I wed her. Me, whose first wife had been a cousin of the Prince of
Pentos. The palace gates were closed to me thereafter, but I did not
care. The price was small enough, for Serra.”
Some may argue that a lot of people in Lys have such features. But wait. Why does Illyrio show such fondness for the boy pretender?
“Good fortune,” Illyrio called after them. “Tell the boy I am sorry
that I will not be with him for his wedding. I will rejoin you in
Westeros. That I swear, by my sweet Serra’s hands.”
Why does he have so much personal interest vested in Aegon's success?
Are you quite certain that Daenerys will make good her brother’s
promises?” “She will, or she will not.” Illyrio bit the egg in half.
“I told you, my little friend, not all that a man does is done for
gain. Believe as you wish, but even fat old fools like me have
friends, and debts of affection to repay.” Liar, thought Tyrion. There
is something in this venture worth more to you than coin or castles.
Why did he have chests full of rich clothes for a young boy at home which he used to dress Tyrion? Why did he have a statue which looks a lot Like Aegon at his manse?
A naked boy stood on the water, poised to duel with a bravo’s blade in hand. He was lithe and handsome, no older than sixteen, with
straight blond hair that brushed his shoulders. So lifelike did he
seem that it took the dwarf a long moment to realize he was made of
painted marble, though his sword shimmered like true steel.
Could it be that the boy is actually Illyrio and Serra's son? Illyrio claims that the statue is actually his own from his youth. If the claim is true, then it is possible that Aegon inherited his looks and physique from Illyrio. If it is false, then why would someone have Aegon's statue in their manse unless they were related by blood and loved each other?
Illyrio was right after all when he said that "Not everything a man does is for personal benefit". Yup somethings are done to avenge ancestors of your wife and help your son claim his rights.
Holes in Varys' Story
And we can not discount that the pretty story that Varys tells about Aegon's escape has a huge flaw. Flaw named, Aegon's death. Aegon believes that Varys smuggled him out of KL and replaced him with a common born child. It was that child whose head got squashed by Gregor Clegane which made the corpse unidentifiable. How did Varys know that Mountain will kill the boy in such a way that his corpse would not be able to be identified? Can he see the future?
If Mountain had not squashed the head of the child, It would have been obvious for Ser Jaime Lannister at least that the babe was not Aegon Targaryen. Ser Barristan Selmy was not present at that time otherwise he would have known as well about the fake child. Kingsguard spent their lives in presence of Royal family. It is unlikely that they would not know the child prince by sight. Pycelle would also be able to figure out that the child was not the prince since he was the grand maester and most likely saw to the birth of the prince and his later medical care.
What's up with Varys?
So why on Earth is Varys helping Aegon? We know the story of how Varys was cut.
With a long hooked blade, he sliced me root and stem, chanting all the
while. I watched him burn my manly parts on a brazier. The flames
turned blue, and I heard a voice answer his call, though I did not
understand the words they spoke.
From Melisandre's antics we know that sorcerers use people with Royal blood to perform certain forms of magic. Why did that sorcerer choose Varys? What was so special about him? Royal Blood? Where would he get that? He can't be a lost descendant of Daemon I Blackfyre who was son of King Aegon IV Targaryen, can he? Does Varys' hair grow a distinctive color of silver and gold which marks those with Valyrian blood in them? Oh wait, yes he is bald. How convenient!
Varys, is most likely, a Blackfyre. Since he is an eunuch, he can't hope to take the throne and continue house Blackfyre. Which is why he is helping a fellow blackfyre who can procreate and rule. That fellow Black dragon is our little Aegon.
Another theory is that Varys is brother of Serra, alleged mother of Aegon. Varys is also matrilineally descended from house Blackfyre. So he is helping his nephew Aegon take the throne which their great ancestor Daemon I Blackfyre had fought for.
Meribald's rusted Red dragon
There is also something that Septon Meribald said:
He forged a new sign for the yard, a three-headed dragon of black
iron that he hung from a wooden post.
One of the dragon’s heads washed up on the Quiet Isle many years
later, though by that time it was red with rust
Three headed Black Dragon is the sigil of House Blackfyre. This could possibly be an euphemism for Aegon. A black dragon washed up across the water [Narrow sea in this case] and with time and rust [time and falsehood], it started looking red. [Red dragon is sigil of House Targaryen].
Why pose the rusted Black Dragon as Red Dragon?
But why use the Targaryen ruse? Why not go and claim the throne as a Blackfyre?
Because it's been too long. Nobody in Westeros cares about Blackfyres now. The generation that knew and loved Daemon Blackfyre is long dead. For people now, they are just a part of history about which no one except the maesters care about.That is why they need Aegon to pose as a Targaryen and take this secret to their graves.
Aegon himself does not know his true lineage because Illyrio and Varys kept it a secret from him. What he does not know, he cannot let slip.
Nevertheless, Aegon is still from a cadet branch of House Targaryen. People may still call him a fraud but if Daenerys takes Aegon in her arms as a nephew, no one will ever need to doubt his parentage. As Harry Strickland said in ADWD Chapter "The Lost Lord":
"We need the girl. We need the marriage. If Daenerys accepts our
princeling and takes him for her consort, The seven kingdoms will do
But What if Daenerys challenges him to claim a dragon to prove his blood? No problem, Aegon is also blood of the dragon, he can claim a dragon just as much as Daenerys can after which even Dany would not doubt his parentage.
So in all probability, Aegon is a Blackfyre and thus Golden company is honor bound to answer his call to arms. The question however remains that do the men of the company know that? I think not. It's too sensitive sort of information to entrust common men-at-arms with. Do high officers know? They most probably do. They probably know even more than Aegon and Jon Connington do themselves.
Myles Toyne who belonged to an old house loyal to Blackfyres made the pact to support Aegon on behalf of GC. He was an old man and had most likely fought in last Blackfyre rebellion in which Ser Barristan Selmy killed Maelys the Monstrous and ended the male line of House Blackfyre. No man would be a bigger Blackfyre loyalist than him.
The officers had probably conferred among themselves before meeting Aegon because that is what happened when Jon Connington announced that Aegon is son of Rhaegar Targaryen.
Silence greeted his announcement. Someone cleared his throat. One of
the Coles refilled his wine cup from the flagon. Gorys Edoryen played
with one of his corkscrew ringlets and murmured something in a tongue
Griff did not know. Laswell Peake coughed, Mandrake and Lothston
exchanged a glance. They know, Griff realized then. They have known
all along. He turned to look at Harry Strickland. “When did you tell
A Wiser man would have asked "What did you tell them?".
It was clear that it was Jon who was in the dark, not the captains of the Golden Company. They were already aware of who Aegon was and were acting on a plan. There was a reason that GC officers conferred among each other before receiving Jon Con and Aegon.
So of course when Aegon asked for Golden Company's help, This is what the stalwarts of house Blackfyre replied:
"Prince Aegon", said Tristan Rivers. "We are your men. Is this your
wish that we sail West instead of East?"
Remember, these men who are soul of obedience in front of Aegon are the same men who mocked Viserys and laughed at him. But of course neither Aegon nor Jon Connington know about that.
What does reputation as Sell Swords mean when you have the chance to follow your true purpose and your true king? A chance to fulfill dreams of your forefathers? The dream of marching into Red Keep with Bittersteel's skull on top of a spear and a Blackfyre King climbing the stairs to the Iron Throne at last. The dream of getting back everything that was lost because of their loyalty to House Blackfyre. That dream is more important than any contract with Cheese Lords of Essos.
And What better time for fulfilling that dream than now? A Child King who is a suspected bastard with allegedly no claim sits on the Iron throne. The realm is ruined by horrific warfare. Lords and nobles are divided. There is chaos in the whole realm. What would happen when people learn that a Messiah has finally come from across the narrow sea? A Messiah who is none other than son of their beloved Prince Rhaegar & the only (alleged) true heir to the throne? Someone who will restore order and bring justice and peace to realm like his noble ancestors did?
However, Daenerys would have suspected something odd with GC giving Targaryens their allegiance since she knows how they reacted to the request before.......... Unless of course, the Plan of Varys and Illyrio never had any place for Daenerys anyways except gaining her endorsement of Aegon's lineage. After that they would have removed Dany from Aegon's path, leaving no other rival claimants to the throne....or dragons.