I would like to create a Linux based OS for a VR headset that I'm developing. From what I understand, the Linux kernel uses the GPL-2 license which allows for commercial use but it also requires you to publish your source code. How is Tesla able to sell a physical product that runs on a Linux OS while also being able to keep their source code private and how can I do the same?
The GPL only applies to derivative works of the GPL-covered software. In particular: if you modify the covered software, or if you include the covered software (whether in whole or in part) into another software such as by copying code or by linking a library.
The GPL does not extend to other programs, even if those other programs communicate with the GPL-covered program.
So it is perfectly possible to create proprietary applications that run on the GPL-covered Linux kernel. This is quite common. I was just playing a proprietary game on my Linux-based system. Android smartphones run proprietary Google software. And many cars run a proprietary user interface on top of a Linux kernel.
This would be different for drivers. In general, Linux drivers must be GPL-covered as well. In fact, every kernel module must declare its license in a metadata field, and will not get access to kernel methods if it has a GPL-incompatible license. As an extra permission (that goes beyond what would be required by the default GPL), non-GPL kernel modules still get access to basic features. So if Tesla had created a kernel module that e.g. acts as a driver for special hardware in the cars, they would likely have to open-source that as well.
In practice, many vendors that use embedded Linux are not particularly forthcoming with the source code of the Linux kernel they are using. Sometimes this is ignorance about the license conditions, sometimes this seems to be wilful obstruction. Either is a license violation.
Tesla has started releasing Linux source code in 2018, almost five years after they were initially asked. That they moved forward is in large parts thanks to the Software Freedom Conservancy.
What e.g. Google does with Android (Linux-based) is to publish the open source pieces (the kernel plus any patches, libraries, ...), while keeping propietary pieces (like programs running on said kernel) private. That is legally OK.
Note that GPLv2 does allow you to make it so no modified kernel can be installed on the device (for example, ship it on an embedded ROM, or require a signed piece of software). Look around for the discussion around TiVo and Linux for the gory details.
In case of any important decision to make, ask your own lawyer, and make sure she is knowledgeable on open source and software.
You might consider switching to some BSD kernel, they have less strings attached.