Here you go, not tested but it should work.
var locktospec: array[1..32] of boolean;
function OnCommand(ID: Byte; Text: string): boolean;
var target: byte;
begin
if (getpiece(text,' ',0) = '/locktospec') then if (getpiece(text,' ',1) <> nil) then begin
if getplayerstat(strtoint(getpiece(text,' ',1)),'active')=true then begin
target := strtoint(getpiece(text,' ',1));
locktospec[target] := not locktospec[target];
if locktospec[target] = true then command('/setteam5 '+inttostr(target));
end else writeconsole(ID,'There is no player using ID #'+inttostr(target),$ffff0000);
end else writeconsole(ID,'You must specify a player id!',$ffff0000);
end;
procedure OnJoinTeam(ID, Team: byte);
begin
if (locktospec[ID] = true) AND (team <> 5) then command('/setteam5 '+inttostr(ID));
end;
procedure OnJoinGame(ID, Team: byte);
begin
locktospec[ID] := false;
end;