As I understand it this is an evolution from the PIE reflexive to a new mediopassive.
PIE is often reconstructed as having two voices, active and mediopassive. Classical Latin had separate verb forms in -r that marked the mediopassive. (This -r form was also found throughout Italoceltic, Tocharian, and Hittite.)
Separately, PIE *se- -> Classical Latin sē (sēsē, sibi, suī) was almost purely a reflexive marker, with some use as a reciprocal marker (e.g. inter sē).
As the Romance languages developed, the -r mediopassive became disused even for deponent verbs. I'm not confident why this happened; perhaps it was due to forms becoming homophonous. Anyway, with the loss of the old mediopassive a new form was adopted for the voice. The reflexive sē filled this role. In the daughter languages sē -> Fr, Es, Pt, Ro se, It si.
So in Portuguese, and many of the other Romance languages, the reflexive/reciprocal and mediopassive are formed using se. The "subject indetermination" and "passiving" functions you describe use se as part of this new "mediopassive"; i.e., indeterminate or impersonal subjects regarded as a middle voice.
EDIT: Miller (2010) has a treatment of this question in "The Mediopassive: Latin to Romance":
forms replaced the ‐r forms in different structures at different
times. The replacement began in the ergative verbs where ‘I sank
myself’ had a bound anaphor in contrast to the lack of agentivity in
the type ‘the ship sank itself’ , reanalyzed as an anticausative with
reflexive merged in a projection for derived imperfectivity.
Subsequently, the sē construction replaced the ‐r forms in certain
other structures, and finally the middle and impersonal, but not the
passive (within Latin, at least).