You cannot drive through Joshua Tree National Park without paying the entry fee or having an NPS parks pass, even if you only plan on commuting. As of 2023, the entry fee for a 7 day vehicle pass (the cheapest available) is $30.
If you have an annual national park pass then entry to Joshua Tree National Park will be included.