I guess they are the unique IDs (I'll refer to tags as IDs in my answer) of each clan and each player that SuperCell was using from when they developed which also allowed players and clans to have the same display names.
They made the clan ID visible recently because the number of players and clans has been becoming so large that it was getting difficult for players to find the right clan among the multitude of clans if one particular clan name was popular.
The search tool to find clans in the game cannot display all the clans that matches a searched name so there came the advanced search tool with the tags added and a bunch of other options like trophy restriction and clan size.
The player ID on the other hand was made visible just after the option of one time username change had been implemented. I cannot say for sure why that was done, but my guess is that it makes it easier to identify players even if they changed their username... even though I would say it's not that practical to remember the random series of characters. The only use I can think of where that hash will benefit players would be if a clan does not want a particular player in their clan. That particular player could change his/her name but not the hash tag so that could easily be found out.