The short version is that its in limited supply, it has luxury value (think jewelry or artisan crafting), and its doesn't corrode. So it's a supply and demand issue. There is basically always the same amount, kings want it, and it doesn't ever disappear.
It s superior to currency because while (for example) the US dollar will always have value as long as you pay taxes with it, there is not a limited supply
It is superior to bartering because while (for example) a chicken has value due to its utility as food, it naturally disappears (because you ate it or it died).
Gold and other precious metals sort of sit in the middle ground as the "next best thing" to almost everything that humans want. So it remains a useful means of preserving and communicating value.
It s superior to currency because while (for example) the US dollar will always have value as long as you pay taxes with it, there is not a limited supply
It is superior to bartering because while (for example) a chicken has value due to its utility as food, it naturally disappears (because you ate it or it died).
Gold and other precious metals sort of sit in the middle ground as the "next best thing" to almost everything that humans want. So it remains a useful means of preserving and communicating value.