Were pets allowed, or even if not expressly permitted, tolerated?
Did attitudes vary based on the theater, commanding officers, or even ship types? Were there any pets in submarines?
Pets were common aboard Royal Navy vessels during the period. Cats were particularly common, as they could catch rats and other vermin. However, other ships might have dogs, and maybe even more exotic animals. Ships based outside the UK might well acquire local animals, particularly ones symbolic of where they were based; for example, it was common for ships based at Esquimalt on Canada's west coast to adopt black bear cubs as mascots. Individuals could also acquire their own pets, though this was largely up to the policy of the individual ship. Typically, men could acquire small pets like songbirds without needing permission. Larger pets needed the permission of the Commander on large ships or 1st Lieutenant on smaller ones (i.e. the Executive Officer in USN parlance). As a result ships that visited Malta or the Canary Islands would often leave with hundreds of birds aboard.
Submarines generally did not carry pets, due to the lack of room. However, it was not unknown for submarines to pick up pets from ships they sank. In May 1940, Spearfish picked up a dog from a Danish fishing boat, while in the Mediterranean in 1943, Ursula rescued a dog from a Vichy freighter. These were not kept aboard the boats, but were instead transferred to the depot ship at the submarine's base. The 10th Submarine Flotilla, based at Malta, also kept pigs to supplement their rations.
The RN also had its own zoo, to house those mascots that outgrew the ships that owned them, or that couldn't easily be looked after aboard a warship. The zoo was at the gunnery training base of HMS Excellent, on Portsmouth's Whale Island. It opened in 1893, but closed in 1940 due to the threat of German bombs aimed at the rest of the naval base. The zoo had a lot of animals, including polar bears and lions. Some of these had been naval mascots, but others had been donated by other countries - for example, two of the polar bears were donated by the Norwegian government. Once the zoo closed down, the animals were dispersed to zoos around the country.