Is there a way (script/code) that the typeface would know that there is a specific letter that is being used throughout the text and that every time it is repeated to use a different stylistic set?
The image shows the Heh-ar.init used and Here I changed it manually for many letters (selecting the glyph in indesign). Is there a way for it to do this on its own so the user has this hand writting feel?
You cannot analyse the text in OpenType. All you can do is cycles of pre-determined substitutions that look random. OpenType Cookbook has examples on how to do it: https://opentypecookbook.com/common-techniques/
But it means you need to have alternates for all glyphs, which may be too much. Maybe you could select the conditions randomly like this:
sub dal-ar space heh-ar.init' by heh-ar.init.ss01;
sub heh-ar.init' yeh-ar by heh-ar.init.ss01;
But the standard approach requires that you have the same number of alternates in all letters (and all initial, medial, and finals). I would say THAT is too much.