It's a holdover from the old Gold Standards. Gold standard regulation required all banks, including the central bank to hold gold as a regulatory asset. In the last gold standard, the Bretton Woods regime, the US in particular had to hold gold to back the dollar. The requirement went away with the collapse of the Bretton Woods agreement in 1973, but the gold didn't.
These days there isn't any requirement to hold gold, and indeed some countries - notably the UK in 1999 and 2002 have sold off significant amounts of their bank holdings. (Note though, it's been suggested there were stability issues behind this sale.) Gold on the Federal Reserve's book isn't even held at market prices, it's marked to a notional statutory value of ~$42.
By the same token, there isn't any requirement not to hold it, so why sell it? There tends to be a lot of inertia in these kinds of systems.
Interestingly, an examination of central bank annual reports shows a fair amount of variation in what they use for their assets. While government debt in the form of treasuries is usually present, the Norwegian central bank holds market securities - presumably due to a lack of government debt. The Federal Reserve added securitized loans in the wake of the 2007 crash in order to stabilise their financial system.