How do DVDs avoid the blockyness that plagues dark scenes in most video files? When a DVD is ripped to a file on a computer the dark scenes typically get compressed to the point of illegibility; huge squares of black are all set to the same value, removing all the detail. This is often seen in video files posted to the internet.  

I get why it happens; The difference between two shades of black is quite easily to perceive, but to the compression algorithm it is a tiny difference, so the two shades are set to one value to save space. 

However, this effect is obviously avoided on the DVD itself. How do they do this, and why don't the compression methods used when ripping the DVD to a file also do this? I mean, the DVD format and codecs are old, far older the the ones used online today. So why does this problem appear when ripping the file?
A single layer DVD has about 4.5 GB of capacity, a dual layer DVD has about 8.5 GB of capacity. Some of this space is taken up by menus and special features, but that still leaves plenty of room for video with minimal compression.

Take a look at the "blocky" videos - they have probably been re-compressed down to 700MB (so they can fit on a CD-R blank) or 1GB (because people love round numbers). Shrinking the video down requires more aggressive compression settings, which results in lower quality video. Sometimes this lower quality exhibits itself in terms of large blocky dark regions.

The other issue is that the compression algorithms used on DVD video are lossy. When you transcode to a lower bitrate codec, the software uncompresses and then recompresses the video. Since the compression is lossy, the uncompress step recovers imperfect video, and that imperfect video is then compressed. This slightly compounds the quality problems.

If you want to make a perfect copy, just rip out the original video. Don't transcode it to a new format.