I was really confused by the error:
Unity.Services.Core.ServicesInitializationException: The Leaderboards service has not been initialized. Please initialize Unity Services.
at Unity.Services.Leaderboards.LeaderboardsService.get_Instance () [0x00012] in .\Library\PackageCache\com.unity.services.leaderboards@4afe9822e038\Runtime\LeaderboardsService.cs:42
at UGSLeaderboardManager.GetPlayerScore (System.String leaderboardId, System.Int32 defaultScore) [0x0001f] in...
(This with a very long stack trace)
The weird thing was that I had the same code in 2 projects, and it worked in one project, but not the other. After struggling to find the difference between the 2 projects, I saw that the working project was running Leaderboards version 2.3.3, and the broken project version 2.3.4. After upgrading the working project to version 2.3.4 the same error appeared. So it seems there is something wrong with Leaderboards version 2.3.4.
After downgrading back to 2.3.3 it worked again. So I'll keep using that version.