As mono states, robbing one aircraft to service another is legal and fairly commonplace. The commonality of the parts has to be thoroughly researched by the engineers doing the job and this includes compatibility of part numbers, serial numbers, modification state, service bulletin status and for twin engine aircraft, ETOPS approval. The actual robbery procedure will only be carried out once all other avenues for sourcing spares have been exhausted. Some form of record has to be kept of all robberies that can be seen during CAA or QA dept audits. If the number is excessive then obviously there are problems with logistics, spares holdings or overhaul turnround times that have to be resolved.
Master Slug, the details in your post are vague and in this instance the exercise didn't appear to pay off but the fact that several aircraft were u/s may not have been down to this procedure being carried out but a totally unrelated problem.