The Death Star superlaser, despite its name, is a particle beam weapon and not actually a laser (lasers interact differently than charged particles do with matter).
Even if the Death Star superlaser was actually a laser, it still might not actually work passing through Yavin Prime. Shooting a beam of massless photons would, presumably, ionise the gases that they passed through, turning those gases into plasma. Plasmas can, though do not necessarily always, absorb electromagnetic radiation (photons), so it is possible that by ionising Yavin Prime, the laser itself could be blocked (at least partly) by the plasma it helped to create and is sustaining by firing into it.
However, as stated, the superlaser of a Death Star is not a laser, but is actually a particle beam weapon. A particle beam weapon accelerates charged particles, such as electrons or protons, or in this case, some form on unstable matter sourced from hypermatter, to very high speeds up to just below the speed of light. These massive particles then impact the target with tremendous amounts of kinetic energy.
If you shot a superlaser at a gas giant (planet) like Yavin Prime, the charged particles would collide with the gases in their various states (gases in gas giants turn into liquids as you descend into them as the pressure increases, plus gas giants can have solid materials in them and some may even have solid cores) and its kinetic energy would be imparted, at least in part, to the planet itself rather than its target, Yavin IV.