If the ball was out of touch before the contact it is not a foul. From your description it sounds like ref properly cautioned defending player but he couldn't award a foul since a foul can only be committed by a player while the ball is in play. So the fact the offense took place in the penalty box is not material and the correct restart is a goal kick. Now if the ball wasn't yet out of touch it would be a pk.