I purchased a used Nintendo Switch Smash Bros edition which still has its previous owner's data on it, is there a way to do a factory reset (so I can create my own profile) without losing the game which is already installed on the console? I don't have a physical card for it, only the digital version.
Since the device has someone else's account on it, once you reset it, if you don't have access to that account, you'd lose access to anything downloaded on the console. According to this help page from Nintendo it states that the games are tied to whatever Nintendo Account was used to download them.
So no, if you factory reset the Switch, you won't have access to any downloaded games that were on it, if they weren't bought by you on a Nintendo account you have the login information for.