Apps are sandboxed, but WebKit runs outside the sandbox with additional privileges such as JIT and multiple processes and communicates with the app through IPC. This change is allowing third-party code to also run with these privileges as long as they follow certain security standards.
iMessage has also been the main source of hacks for iPhones for years if not decades. Apple really struggle with securing iMessage.
It definitely does not need to run all the time, it could be woken up by incoming notification like all other apps (and I hope it is how it actually works).