Maybe in Jass there is an easier way, but here's my advice:
EASY WAY
Event
Unit - A unit Finishes construction
Condition (if you only want to apply to some buildings, do that here)
Action
Set constructor = (Random unit from (Units within 120.00 of (Position of (Constructed structure)) matching ((Unit-type of (Matching unit)) Equal to Peasant)))
Unit - Remove constructor from the game
Unit - Kill constructor
Replace "Peasant" with whatever builds the building. You may need to change the "120" to a larger number depending on pathing. This trigger works by picking a random peasant near any finished building and killing it. It's imprecise and you may end up killing the wrong peasant unfortunately. That won't be a big deal unless the other peasant is constructing something. It will also only remove one peasant if you have multiple peasants building
HARD WAY
I did this for humans, because you didn't mention which race you were working with. Make a trigger that detects every time a human peasant casts "repair." Every human building starts with a peasant casting repair. Then set the custom value of the peasant and the building to the same integer. Something like this:
event - a unit casts an ability
condition -
ability = repair
action =
set custom value of casting unit to X
set custom value of target of cast ability to X
set X = X+1
if X = 100 then set X = 1 else do nothing
That trigger links peasants and the buildings they create by giving them the same custom value. Then another trigger runs when the building is complete.
Event
Unit - A unit Finishes construction
Action
set TotalPeasants = number of living peasants owned by owner of constructed unit
For each interger A from 1 to TotalPeasants
set TempUnit = random unit of TotalPeasants
If custom value of TempUnit = custom value of constructed unit,
then: set constructor = TempUnit
else: do nothing
Unit - Remove constructor
Unit - Kill constructor
That second trigger will go through all your peasants until it finds the one with the same custom value (set in trigger 1) as the constructed building. It then removes and kills the unit.
Now let's see if someone can find a way of doing all this with one line...