Interesting question. There are really two parts to the answer.
Firstly, there's no single 'way' to do acheivements. The designers come up with what they want the acheivement to be, and then we code in whatever stat tracking systems we need in order to know when it's been acquired. There's no right or wrong way to do this part, it's much the same question as asking 'how do you make an AI walk?' or 'how do you make the camera avoid the ceiling?'. Some of the achievements were coded by the gameplay team (things like The Black Knight), others are detected in the scripts (such as collecting all the books in Knothole Island).
However, once you have the means to detect when an achievement is unlocked you actually unlock it by making calls on the achievement system in the XDK. There's a standardised 'game description' file that all 360 games must have and this contains all the stuff you see about a game when you examine it on the dashboard. As part of that, it has the names and icons for the acheivements. There are functions in the XDK for things like 'unlock achievement number X for the profile active on quadrant Y'. The system automatically handles the rest of it (updating your profile, posting the data to the Live! servers etc...)