The tiny Mediterranean territory, governed by Britain since the 18th century but claimed by neighbouring Spain, is the subject of frequent squabbles between the two countries.
Officers arrested the two for a suspected breach of the peace after the television crew raised the flag while filming, a Gibraltar police spokesman told AFP. They were later released on bail, the force said.
Telemadrid, a conservative public television channel in the Spanish capital, identified the journalists as Cake Minuesa, the presenter of its current affairs show "Citizen Cake", and a cameraman.
"While they were filming a group of people started insulting them. The police arrived and then they (the journalists) were detained," said the show's producer José Luis León said in a broadcast on the channel late on Wednesday evening.
"It seems the intention is to accuse them of a breach of public order for placing a flag on a public beach in Gibraltar."
Madrid and London have clashed frequently in the past year over Gibraltar, whose 30,000-strong population is staunchly pro-British, squabbling notably over rights to the waters off the territory.
Britain has accused Spanish police of causing long queues at the border, while Madrid blames Gibraltar for an increase in tobacco smuggling to Spain.