Secondary dominants take upper tensions from the key of the piece.
Diminished 7ths take upper tensions from the key of the piece.
Makes sense.
But substitute Vs (which are a form of secondary dominant) take upper tensions from the key of the chord. Why?
E.g. Db 7th will have an Eb G Bb on top (9, #11, 13). But sometimes they'll also take a #9 - which is not in the key of the chord. How were these tensions derived?
Update
Some of the comments and answers amount to "you can add alterations however it sounds good". But my first year jazz theory teacher said the alterations are used because of the underlying mode. For instance, the V7 of a major key will not have altered tensions (e.g. G7 in C major will not have Ab), but in a minor mode they will (e.g. G7 in C harmonic minor will have Ab).
Below you can see all the available tensions in each mode in this chart in orange:
Gurney's answer that we use the alterations for a tritone sub's chord's key, rather than the song's key seems most correct: "It is harder to make the listener aware that you are using a tritone substitution."
But that doesn't explain why you may use a #9 only in subV/I, subV/IV, and subV/V (when you are resolving to a major key), and not the minors. I feel there is still an underyling principle here that could be explained faster and more elegantly.