If Princess Anne dies during the reign of her nephew King William V, is there a written law of how soon he can give the title of Princess Royal to Charlotte?
No. There is no rule about when or if the title is given.
Historical precedence:
-Anne received it in 1987- Mary, Countess Harewood died in 1965. (22 years)
-Mary received it in 1932- Louise died January 4, 1931 (3 days short of 1 year anniversary of Louise's death, Mary got the title on January 1 1932)
-Louise received it in 1905- Victoria (German empress) died in 1901 (4 years)
-Victoria received it in 1841- Charlotte (queen of Wurtemberg) died in 1828 (13 years)
-Charlotte received it in 1789- Anne (princess or orange) died in 1759 (30 years)
-Anne got it in 1727- Louisa Maria had died in 1712 (15 years)
-Louise Maria got it in 1692- Mary had died in 1660 (32 years)
-Mary- was the first and was bestowed the title in 1642 at age 11
The longer waits often had to do with no one to fill the role.
-Charlotte died 12 years before Queen Victoria had her first daughter. Victoria later bestowed the title upon her 1 year old daughter.
-When Anne of Orange died, there was no one to fill the title. Charlotte was born 8 years later. Charlotte's father waited till she was 22 to give her it.
-Anne was only 3 when Louise Maria died. She was given the title at the age of 18
Mary and Louisa Maria got it at birth. It was the tradition from the French court that they adopted, that the eldest daughter of the sovereign, was Princess Royal. Louisa Maria though it wasn't common to use it for her, it fell out of fashion between Mary and Anne.
It really depends on when Anne dies really. If Charlotte is an adult, and a full working royal when Anne dies, it may only be a few years before she is given the title. Or they may choose to wait as done with Anne.