Why is 輩 in 先輩 pronounced ぱい while 輩 in 後輩 is pronounced はい?


I wonder in this case if there is any rule that turns H to P.




**TL;DR**  
In Japanese (native) and Sino-Japanese words, ん and っ make the next consonant
//h// to //p//. The sound change is a grammatical demand that no longer has
phonetic ground, as much as English _criti **c**_ vs _criti **c** ize_.

* * *

**Long story**  
Once upon a time, the Japanese consonant that we today call //h// had the
sound [[p]]. This sound was weakened to [[ɸ]] by at latest 10th c.
([母は昔はパパだった](http://www.iciea.jp/i-news/pdf/107/i-News107-15.pdf)), then to
[[h]]-like sounds (except ふ) by at latest 18th c.
([ハマの二つは唇の軽重](http://ijustat.com/nihongo/uirou.html)). But there are two cases
that these changes were met with resistance.

  1. //p// preceded by consonantal element, now converged into either ん (nasal stop) or っ (reduplication)

> 歩 [[po]] → [[ho]] "step" : 一歩 [[it.po]] → [[ippo]] "one step"  
>  歯 [[pa]] → [[ha]] : 出歯 [[de.ba]] "bucktoothed"
> ([rendaku](https://en.wikipedia.org/wiki/Rendaku)) : 出っ歯 [[deʔ.pa]] →
> [[deppa]] "bucktoothed (slangy)"  
>  輩 [[pai]] → [[hai]] "fellow" : 先輩 [[sen.pai]] → [[sempai]] "senior"

  2. mimetic words; that carry sound symbolism unlike usual words

> ぴかぴか [[pikapika]] < 光 [[pikaɾi]] → [[çikaɾi]] "light"  
>  ぱたぱた [[patapata]] < はたく [[pataku]] → [[hatakɯ]] "pat, rap"

From today's perspective, it seems that //h// occasionally turns into //p//,
but it's actually //p// is occasionally retained until today.

**PS**  
ヨーロッパ, the Japanese transcription of Portuguese
[_Europa_](https://en.wiktionary.org/wiki/Europa#Portuguese), attests two
important facts at the Late Middle Japanese stage: (1) reduction of diphthongs
//eu// → //joo//; (2) //p// unable to appear in the middle of word without
reduplication *//-pa// → //-Qpa//.




**TL;DR**  
In Japanese (native) and Sino-Japanese words, ん and っ make the next consonant
//h// to //p//. The sound change is a grammatical demand that no longer has
phonetic ground, as much as English _criti **c**_ vs _criti **c** ize_.

* * *

**Long story**  
Once upon a time, the Japanese consonant that we today call //h// had the
sound [[p]]. This sound was weakened to [[ɸ]] by at latest 10th c.
([母は昔はパパだった](http://www.iciea.jp/i-news/pdf/107/i-News107-15.pdf)), then to
[[h]]-like sounds (except ふ) by at latest 18th c.
([ハマの二つは唇の軽重](http://ijustat.com/nihongo/uirou.html)). But there are two cases
that these changes were met with resistance.

  1. //p// preceded by consonantal element, now converged into either ん (nasal stop) or っ (reduplication)

> 歩 [[po]] → [[ho]] "step" : 一歩 [[it.po]] → [[ippo]] "one step"  
>  歯 [[pa]] → [[ha]] : 出歯 [[de.ba]] "bucktoothed"
> ([rendaku](https://en.wikipedia.org/wiki/Rendaku)) : 出っ歯 [[deʔ.pa]] →
> [[deppa]] "bucktoothed (slangy)"  
>  輩 [[pai]] → [[hai]] "fellow" : 先輩 [[sen.pai]] → [[sempai]] "senior"

  2. mimetic words; that carry sound symbolism unlike usual words

> ぴかぴか [[pikapika]] < 光 [[pikaɾi]] → [[çikaɾi]] "light"  
>  ぱたぱた [[patapata]] < はたく [[pataku]] → [[hatakɯ]] "pat, rap"

From today's perspective, it seems that //h// occasionally turns into //p//,
but it's actually //p// is occasionally retained until today.

**PS**  
ヨーロッパ, the Japanese transcription of Portuguese
[_Europa_](https://en.wiktionary.org/wiki/Europa#Portuguese), attests two
important facts at the Late Middle Japanese stage: (1) reduction of diphthongs
//eu// → //joo//; (2) //p// unable to appear in the middle of word without
reduplication *//-pa// → //-Qpa//.

