Coding a priority encoder
One approach would be for each of the 25 inputs to either show 0 if deselected, or it's own 5-bit priority value P(i) if selected. Throw all the intermediate values into a sorting network that returns the maximum priority shown in a particular cycle. If you then have a comparator for each input to see if it's show priority equals the maximum as a single bit per input, then use a classic priority encoder technique (e.g. bitscan) on those bits.

Total storage for all priority bits is 25*5 as @Dave_Tweed mentions.