asp.net core is a side by side update. that is a folder each created for each version. by default an asp.net core built for <major>.<minor> will run the lastest patch version of the <major>.<minor> unlike previous .net frameworks, for the asp.net core to run a later major/minor version it must be recompiled. when installing a patch version, it generally safe to delete the earlier versions.
while 5.0.17 is the lastest version of net 5, it has been out of support since May 2022. .net 6 support will end this November. you should probably have a plan to upgrade all your asp.net sites to net 8.
there is no handy way to tell which .net versions are active on a server. if you have list open file support, you could check which .net core folders are in use.