If I'm playing on the switch while its connected to the tv can inkay evolve?
Evolving Inkay REQUIRES the Switch to be in Handheld mode. You cannot do it while docked.
To evolve Inkay into Malamar, your Inkay has to be at least level 30 and, while it levels, you have to be holding your Nintendo Switch console upside down. Yep, you need to take it out of the dock.
Source
However, there's another requirement: once Inkay hits level 30, the Nintendo Switch needs to be in portable mode and must be flipped upside down. This means that if a Switch Pro controller is connected or if the Switch is in the dock, your Inkay will never evolve.
I have also done this numerous times and I know this to be true.
Hope this helps!
Turn your joycons/controller upside down, and it will work.