TCP offers several capabilities over UDP like retransmission to guarantee data is received. A large UDP datagram can be fragmented into multiple IP packets. This is done on layer 3 when it's detected that, given the datagram size, the packet will be larger than the link MTU. Because UDP can't handle retransmission, if any of the datagram fragments are lost the entire UDP datagram is lost. This is quite inefficient. For large datagrams, DNS prefers to break them down to multiple ordered TCP segments. Each of these segments is packaged into its own packet and can be retransmitted if not received by the destination. Duplicate segments can also be detected. Basically, TCP handles failure much better hence more efficient for large datagrams.
UDP based protocols like DNS cap the UDP datagram size to around 512 bytes because this size guarantees the datagram won't be fragmented and hence losing one fragment leads to losing the entire datagram. It's around 512 because, in the IPv4 specifications, hosts should be able to handle packets that are at least 576 bytes large (which is usually well below most link MTUs). Since the IPv4 header can be up to 60 bytes large (20-byte header plus up to 40 bytes of options), 516 bytes (576 - 60) is the maximum size of the IP payload to guarantee not fragmenting.