In 1917, King George V decided to change the name of the house from Saxe-Coburg-Gotha to Windsor.
This change happened because of the anti-Germany sentiments that were around at the start of World War I. He chose Windsor because of Windsor Castle, one of the family's properties.
He also decided that Windsor was to become not just the name of the dynasty but the royal family's surname as well.
Things stayed that way until Queen Elizabeth II came to power.
After marrying Philip Mountbatten, the couple decided they wanted to differentiate their own branch of the family tree and so the hyphenated surname Mountbatten-Windsor was born.
The rules state that royals with titles like "His Royal Highness Prince" or "His Royal Highness Princess" do not need to use a surname but they can use it if they want to.
In fact, they can even change back to older rules if they want. For example, when Prince William and Prince Harry served in the military, they went by William Wales and Harry Wales, something they could do because their father, Prince Charles, is Prince of Wales.
Other royals have veered off the rules a bit too. Princess Anne's children, for example, took their father's surname: Phillips.
The reality is that the surname is there but no one is really forced to use it. While, technically, their surname is still Windsor, the Queen's direct descendants can use Mountbatten-Windsor if they want or need, but most of them choose not to bother with surnames at all.