As a starting point: you need to override "MeleeStartingHeroLimit" from blizzard.j with your own function, that's where each individual hero is limited if I read this right. You need to replace the constant "bj_MELEE_HERO_TYPE_LIMIT" inside with your own, by default it's set to 1 i.e. limited to one hero of each type.
Then there're "bj_MELEE_HERO_LIMIT" and "bj_MELEE_MAX_TWINKED_HEROES", "bj_MELEE_STARTING_HERO_TOKENS" - look where they're used.
Finally, if you click each hero in WE you'll find their techtree level requirements.
Tier 1: nothing
Tier 2: Altar = <respective race's town hall level 2> | Market = 'TWN2' Any Tier 2 Hall AND 'TALT' Any Altar
Tier 3: Altar = <respective race's town hall level 3> | Market = 'TWN3' Any Tier 3 Hall AND 'TALT' Any Altar
I didn't find any references to TWN* in blizzard/common.j so this must be hard coded in the game? Bad news. The good news is if you go to "Techtree Requirement List" and select "TWN3" then "Edit Tech Item": There're up to TWN9 levels to choose from. I think if you lift all other restrictions, you could have up to 9 heroes in the game by modifying town hall levels (how??). In the end I'm not sure any of this will work, but in theory everything you need is there. If you don't like how this sounds, you can recreate hero purchase through abilities and track limits using triggers etc.
What I'm thinking, you gotta fake each race's starting castle to be of level 3 somehow. Next upgrade should push it to level 6, and third upgrade to level 9. I don't know how town hall upgrade level is calculated. Maybe you need a chain of building upgrades like in TD but upon finishing the level1->level2 upgrade, set the town hall level to level 6.
Tier1 -> Tier2 -> Tier3 (This is what players start with, what peons can build. Level 1) -> Tier4 (only price and upgrade icon) -> Tier5 -> Tier6 (Level 2) -> Tier7 (only price and upgrade icon) -> Tier8 -> Tier9 (Level 3)
Tier 1, 2, 5, 8 are total dummies town hall units. Tier 4 and Tier 7 need an upgrade cost and icon. With a trigger you set Tier4 to Tier6, and Tier7 to Tier9.