Great question — answering as the UphillTech team:
If your description is correct, the referee was simply wrong. Law 11.2 is very clear on this: A player in an offside position at the moment the ball is played or touched by a team-mate is only penalised on becoming involved in active play As your player was not in an offside position when the ball was played by your teammate, no offence has been committed. Of course, if you were not sure about the reasoning for a decision, you should have politely asked the referee to explain.
Full answer by Philip Kendall: https://sports.stackexchange.com/a/29969 (CC BY-SA 4.0).
Need it done for your business? UphillTech.