To expand upon voretaq7's answer, understanding the history and evolution of transponders can more deeply explain why this is the way it is (for now).
When Allied (US/UK/Others) WWII planes returned from combat missions over Germany and mainland Europe, the (brand new technology) radar controllers had no way of knowing "who" the aircraft were. To solve this problem, aircraft began carrying an electronic box that could transmit a radio signal automatically in order to identify themselves. This system was the original IFF (Identification: Friend or Foe).
This piece of electronic wizardry could be set on the ground by crew members, prior to departure, using an 8-position dial numbered from 0-7. The box would receive a transmission signal from the ground, and then transmit a reply of two bursts of energy per cycle: the first signal was the "I'm beginning my transmission" signal (a slightly louder burst of energy), and the next signal was delayed a specific amount of nano-seconds to match the frequency wavelength (and would be slightly lower in intensity). If the transmitter was set to 0, the delay was nothing. That is, the second burst would be transmitted on the next "instance" following the begin-transmission burst. If set to 1, then there was a 1-step delay after the start-signal... all the way up to 7, which would induce a 7-step delay.
The rudimentary "computers" on the ground, co-located with the radar, would receive these transmissions. Based on the known radio frequency, the timing of these short bursts of energy onto the carrier wavelength could be interpreted back into a number. If the radio on the ground received something like:
START-nothing-nothing-SIGNAL-nothing-nothing-nothing-nothing-nothing-START-nothing-nothing-SIGNAL-nothing-nothing-nothing-nothing-nothing.... then it could be calculated that the box onboard the aircraft was transmitting the "number 2". If the secret number for that day (briefed to pilots before they left) was "2", then the plane was identified as a "FRIEND" in the IFF system. This was the very first transponder prototype. (BTW: It is called a "transponder" because it does two things: it TRANSmits a resPONSE to a specific signal on a specific frequency.)
But the obvious first hurdle was the fact that there were only 8 numbers available, and so the transponder boxes were quickly upgraded to two settings (56 possible code combinations) and then 4 settings (4,096 possible "code" combinations).
But there was still a "problem": the codes were set on the ground and could not be changed. Any mid-mission compromise of the number being used that day prevented aircraft already airborne from changing their codes. The next technological leap was to develop a panel-mounted system where the pilot could change each of the four dials manually.
This technology eventually entered the civilian arena. To distinguish between different types of transponders and who was using them (mostly a frequency issues - military freq vs. civilian freq), different categories came about, called "modes". A "Mode 2" transponder was the above described 4-digit, octal, set-on-the-ground-and-leave-it system. A "Mode 3" transponder was the newer, pilot-sets-it-in-the-air version, but still using military frequencies.
When the civilians began using the same technology on approved civilian frequencies, the designation was "Mode 3-A", often just called a "Mode A" transponder. Combined with the advent of civilian air traffic surveillance radar, controllers could now distinguish "who was who" on their screens, by assigning each aircraft its own unique number. This was great for a while, but the only thing controllers could see was the "blip" and its assigned number. The radar computer could also calculate ground speed, but not altitude. So, the controllers relied on the pilot to report their altitude verbally.
This led to the next technological leap forward in transponders. If that same radio could somehow be connected to the aircraft's pressure system (the same one that drives altimeters and vertical speed indicators), then it could probably somehow be configured to transmit that altitude data as well. That technology was thus invented, and the designation "Mode 3-A/C" was applied to the civilian versions... commonly (and still popular today) called a "Mode C Transponder".
This (finally) gets us to the original question: Why don't aircraft program their own registration numbers into the transponder? Since there are only four octal digits available, there are three immediate problems: first, the numbers 8 and 9 are not usable; second, no letters are available; and third, with only 4096 possible combinations, and way more aircraft than that in the world, it is very highly possible that two aircraft in the same vicinity could possibly have the same number.
The advent of "Mode S" transponders, with "current-day" technology, can now transmit (as well as receive) all kinds of information, including the aircraft's specific identity like the question-asker thought should be the way it is. But, backwards compatibility for all of those aircraft still flying around out there with "Mode C" transponders still requires ATC to assign a unique code to an aircraft and the pilot to plug that number in.
Additional trivia, not directly related to the question: Since Mode C transponders are limited to the numbers 0-7, how can they transmit altitude data that might contain the numbers 8 and 9?
The answer is in an aspect of binary coding called a "Gray Code" (or sometimes a "Gillham Code"). The world's avionics people standardized on a set of codes to represent a set of altitudes in 100-foot increments. As a couple of examples, an aircraft at a pressure altitude of 8,500 feet would send the 4-digit code of 6220. Sitting at a pressure altitude of 0 would result in the code 0620. The receiving ground station would evaluate both the pressure altitude received by the aircraft, as well as the current station pressure setting (commonly called the "altimeter setting"), and convert these into the aircraft's actual MSL altitude for display on the radar screen.
I was able to find this list of altitude-code conversions:
https://web.archive.org/web/20120726003224/http://www.airsport-corp.com/modecascii.txt