I know that for a period of time the B-52 had a tailgunner, but nowadays many heavy bombers lack any turret defense.Why?
There are really two reasons. First, fighter tactics have evolved over time, and second, the role of the B-52 has evolved over time.
Fighters used to depend (heavily) upon getting fairly close to an enemy, and shooting it down with a machine gun. Over the years, guns have become less and less dominant, and instead fighters tend to use missiles from outside a machine gun's effective range.
The B-52 was designed from the beginning to carry nuclear weapons. Nonetheless, it's never been used to actually bomb an enemy with a nuclear weapon.
Early in its life, the B-52 was used to drop conventional bombs on enemies though. During the Vietnam conflict (in particular) B-52s were used to drop thousands of conventional 500 pound bombs on various targets.
The Linebacker II campaign was, perhaps, especially notable. During Linebacker II, 15 B-52s were lost--all of them to surface to air missiles (SAMs) not enemy fighters.
Linebacker II did see some limited success from tail guns as well: two B-52s shot down two MiGs. No B-52 (nor any other aircraft of similar size) has shot down an enemy fighter since.
Now, B-52s act as an aerial platform for launching stand-off weapons. Its normal operation is to fly in low (where it's difficult to detect on radar), and launch from a substantial distance from the target. Since it can be a substantial distance from the target, an enemy would need to defend a much larger perimeter (e.g., a large number of fighters basically blanketing a large area) to stand a decent chance of intercepting it.
Even if we assume an enemy fighter were to intercept the B-52, we get back to the situation with fighter tactics outlined above--they'd be unlikely to get within range of its tail gun anyway.
I was in the United States Air Force (USAF) working B-52's when the tail gunner position was retired. The reason was that it was deemed ineffective. As the answers here point out, fighter aircraft evolved such that medium and long range air-to-air missiles were the primary weapons. This kept fighters out far enough that the tail gun cannot hit.
But another very important reason was that the electronic countermeasures on the B-52s evolved such that it became the primary defense and was very effective.
Another major factor was that the fire control system was dependent on a radar transmitter/receiver. That in itself is a problem, because the radar signal could be detected and identified. When you are flying into enemy territory, you really don't want to do it with a radar transmission signal that says "BUFF OVER HERE WITH LARGE PAYLOAD THAT WILL DO MASSIVE STRATEGIC DAMAGE IF WE GET THROUGH".
It needed to be re-engineered to be more stealth, and the USAF didn't assess the time and cost to do that would pay off.
Because the defending nations stopped sending fighter planes at them to shoot them down at close range (where those guns were effective) and instead launched Ground to Air or Air to Air missiles at them from a larger distance.
This meant that it's more important to defend against missiles than against fighters.
Gun turrets are for defending against aircraft that are within gun range. However, modern fighters will usually lock on and fire missiles long before the fighter is within the range of a gun turret.
Nowadays, you can lock onto planes that you can barely see or even not see at all. On the other hand, you have a very limited effective range with machineguns.
Also, keep in mind that shooting down a plane from another plane is very hard (check videos on gunner training in WWII). Now imagine trying to do so on very fast planes like nowadays fighter jets.
To sum things up, most of the time, you won't even be in range to be able to use your machine guns and, even if you were, it would probably be really hard to defend yourself effectively.
Keep in mind that adding these machineguns weights down the aircraft and might even hinder the installation of more important equipment like flares or jammers.
There was a tailgunner on the B-52 because the use of canons by jet fighters back in the Vietnam war was more common than nowadays.
Modern fighters are usually armed with missiles, with which they can engage from far beyond the range of guns. At least one North Vietnamese fighter was shot down by a B52D's rear gun armament during the Vietnam War, however.
I believe that another reason is to do with the speed of modern bombers. At transsonic speeds old-style gun turrets would be ripped off the plane. On helicopters and other non-transsonic aircraft one can still find modern equivalents of the gun-turret. Have a look at e.g. the Mil Mi-24 https://en.wikipedia.org/wiki/Mil_Mi-24