Dragons are smart beasts who can sense the distress of their riders. A dragon and its rider share a very deep and mysterious bond which is formed at times when either party is either in the crib or egg.
They can sense their rider's likes and dislikes, their enemies, their friends and their families.
Even after Ser Otto had returned to Oldtown, a “queen’s party” still
existed at court; a group of powerful lords friendly to Queen Alicent
and supportive of the rights of her sons. Against them was pitted the
“party of the princess.” King Viserys loved both his wife and daughter
and hated conflict and contention. He strove all his days to keep the
peace between his women and to please both with gifts and gold and
honors. So long as he lived and ruled and kept the balance, the feasts
and tourneys continued as before, and peace prevailed throughout the
realm … though there were some, sharp-eyed, who observed the dragons
of one party snapping and spitting flame at the dragons of the other
party whenever they chanced to pass near each other.
The Rogue Prince
We shall not pretend to any understanding of the bond between dragon and dragonrider; wiser heads have pondered that mystery for
centuries. We do know, however, that dragons are not horses, to be
ridden by any man who throws a saddle on their back. Syrax was the
queen’s dragon. She had never known another rider. Though Prince
Joffrey was known to her by sight and scent, a familiar presence whose
fumbling at her chains excited no alarm, the great yellow she-dragon
wanted no part of him astride her.
The Princess and the Queen
This is not the first time a Dragon has shown some mysterious knowledge of their rider's distress. Queen Helaena's dragon snapped her chains when she jumped from the Red Keep even though the dragon was miles away at the Dragonpit.
The rumor of Queen Helaena’s “murder” was soon on the lips of half
King’s Landing. That it was so quickly believed shows how utterly the
city had turned against their once-beloved queen. Rhaenyra was hated;
Helaena had been loved. Nor had the common folk of the city forgotten
the cruel murder of Prince Jaehaerys by Blood and Cheese. Helaena’s
end had been mercifully swift; one of the spikes took her through the
throat and she died without a sound. At the moment of her death,
across the city atop the Hill of Rhaenys, her dragon Dreamfyre rose
suddenly with a roar that shook the Dragonpit, snapping two of the
chains that bound her. When Queen Alicent was informed of her
daughter’s passing, she rent her garments and pronounced a dire curse
upon her rival. That night King’s Landing rose in bloody riot.
The Princess and the Queen
However in the episode that you describe, Daenerys was in no immediate danger. In the opening games of Daznak's reopening, Drogon was attracted by blood and fire as Dragons are wont to do. He killed the boar and Barsena and ate them both. Barristan Selmy thinks it was the blood and war that attracted Drogon to the pit:
They will come, Ser Barristan might have said. The noise will bring
them, the shouts and screams, the scent of blood. That will draw them
to the battlefield, just as the roar from Daznak's Pit drew Drogon to
the scarlet sands.
ADWD: The Queen's Hand
However, we must note that Drogon has sensed Dany's distress before at the House of the Undying and saved her life.