Free goods concept will not work here as this is an intra-company stock transfer.
I don't think there are any standard workaround as per your business process.
As you are maintaining the relation with X and Y in somewhere in system, then you need to do some development to pick the material Y as second line item in STO from this somewhere.