Did each side build half a building? Did one side build them and then concede the territory to move the border to strike right through the middle of them?
They simply built them.
The Joint Security Area (JSA) is the only place in the DMZ where North Korean and South Korean soldiers are face to face. Outside of the JSA, the soldiers stay back from the border at their respective fence lines.
The JSA rules originally allowed for soldiers from both sides to go anywhere inside of the JSA, on either side of the border. The North Koreans decided to use this right to build guard posts on the southern side of the border while the UN forces did not do this on the northern side. This was allowed until the 1976 Axe Murder Incident where North Korean soldiers attacked a group that was trimming a tree and murdered two US soldiers. In partial response, the ability to cross the line within the JSA was removed, the North Korean guard posts south of the line were demolished, and nobody crosses the line without permission.
As far as how they were built, they simply built them. There are blue buildings and gray buildings on the border - UN and Korean People's Army (KPA) buildings, respectively. These days, if there is maintenance to be done or other work that requires crossing the border, the two sides have a meeting and discuss the logistics.