From Whiptail84 on Reddit:
https://www.reddit.com/r/MinecraftCommands/comments/lwutom/removing_offline_players_from_scoreboard/
#First copy all online players to a temporary scoreboard
execute as @a run scoreboard players operation @s <tempScoreboardName> = @s <ScoreboardName>
#Delete the original scoreboard
scoreboard objectives remove <ScoreboardName>
#Create the scoreboard again
scoreboard objectives add <ScoreboardName> <trigger>
#Copy all players from temporary scoreboard back
execute as @a run scoreboard players operation @s <ScoreboardName> = @s <tempScoreboardName>