Prince Philip was due to accompany the monarch to the state opening of parliament on Wednesday.
The infection arose from "a pre-existing condition", the palace said.
The Duke of Edinburgh, who is to retire from public duties later this year, was admitted to King Edward VII Hospital in London on Tuesday night.
Prince Philip was due to accompany the monarch to the state opening of parliament on Wednesday as well as the Royal Ascot horse races.
Their eldest son Prince Charles, the heir to the throne, accompanied Queen Elizabeth to the Houses of Parliament in his place.
"Prince Philip is in good spirits and is disappointed to be missing the state opening of parliament and Royal Ascot," a Buckingham Palace spokesman said.
"Her Majesty is being kept informed and will attend Royal Ascot as planned."
Prince Philip was by Queen Elizabeth's side on Saturday for Trooping the Colour, her official birthday military parade in London.
Prince Philip traditionally holds his wife's hand as the state opening of parliament as they process through the Palace of Westminster to the throne, where he sits at her side as she reads out her government's programme of legislation.
The prince has been the queen's loyal husband for 70 years and announced his forthcoming retirement in May.
He is the longest-serving consort in British history, and is still in good health for a man of 96.
But the royal family's patriarch, who conducted 219 royal engagements last year, has been gradually reducing his workload in his nineties.
The former naval officer's irascible, no-nonsense approach, combined with his infamous and sometimes politically incorrect off-the-cuff remarks, has not made it easy for people to warm to his style.
But his forthright manner and unwavering devotion to duty and the queen has endeared him to the nation.
And observers say his quips put people at ease -- while also providing a welcome contrast to the queen's seriousness.
Philip met the then Princess Elizabeth just before the outbreak of World War II, and they exchanged letters while he served with the Royal Navy in the Mediterranean and the Pacific.
After their marriage in 1947, they spent time in Malta, where he was posted -- only for their lives to be changed overnight by the premature death of her father, king George VI, in 1952.
He once admitted the curtailment of his promising naval career was "disappointing", but said that "being married to the queen, it seemed to me that my first duty was to serve her in the best way I could".
Although he had a reputation for coldness towards his children, many observers consider Philip the glue that held the royal family together as their offspring went through a series of divorces in the 1990s.
In a rare interview to mark his 90th birthday in 2011, the prince said he carved out his role by "trial and error".
Philip was born on a kitchen table on the Greek island of Corfu on June 10, 1921, the only son of prince Andrew of Greece -- the younger brother of Greece's king Constantine I -- and princess Alice of Battenberg.
Aged just 18 months, his family were evacuated on a British navy ship from politically unstable Greece.
They settled in Paris, and at seven Philip was sent away to school in England.
He became a Royal Navy cadet following the outbreak of war in 1939. By 1945, he was a first lieutenant and was in Tokyo Bay for the Japanese surrender.
When he married he gave up his titles as a prince of Greece and Denmark -- and became a naturalised British subject.
In 2011, he said: "I reckon I've done my bit so I want to enjoy myself a bit now.
"It's better to get out before you reach the sell-by date."