Firstly, you need to distinguish between InterRail, available for European residents, and BritRail, available for non-European residents.
Regarding InterRail, the criterion is that you must have been resident in a country for at least six months
irrespective of nationality to be able to buy an InterRail pass originating in that country. You may not use the InterRail pass in that country, but you may be able to get a discounted ticket to the border with an adjacent country at a discounted price. (This is great for someone who lives in, say, Luxembourg, but bad news if you live in Britain where you have to get across the Channel and no discounts are available).
Residence check: the onus is on the issuing office to check your residence. In practice, this means, for example, that if you buy a pass originating in Britain with a British passport, you are automatically assumed to live in Britain. If you are a non-national, you will be asked for some proof - this will depend on the issuing office in whatever country you live in.
The issuer writes your passport number on the pass - nothing to do with residence - and it is this document which you must produce, if asked, during a ticket check. It would otherwise be completely impracticable - imaging asking an ATW guard to check a Bulgarian residence permit, for example.
