As you say, there doesn't seem to be any way the pronunciation of "s" as "sh" in sugar (and sure) could be related to the “sh” in Persian shakar. Rather, it seems to have developed (apparently irregularly) within English.
Palatalization of /sj/ to /ʃ/, which could also occur in other words historically
The use of the “sh” sound (in IPA, /ʃ/) in sugar and sure developed after they had entered English, via palatalization of the sound /s/ before the palatal glide /j/ (like “y” in “you”). As Jon Purdy explains, these words developed a palatal glide due to the change from the French vowel /y/ (spelled "u") to English /juː/.
The sound /ʃ/ occurs for the same reason in many other words related to sure, such as surety and assure, ensure etc. An analogous change affected the voiced counterpart of /s/, /z/, causing /zj/ to develop in many words to /ʒ/ (the sound at the start of the French name Jacques).
I found a good Quora post by Uri Granta that mentions a third word starting with the letter “s” that is pronounced by modern English speakers with the sound “sh” somewhat often: sumac. However, modern dictionaries also list a pronunciation with /s/ for this word, so it is not as categorical as the other two words. (In fact, the book The Pronunciation of Standard English in America,
by George Philip Krapp (1919), calls [ˈʃuːmæk] for sumach [sic] a dialectal pronunciation (p 124), and says it is not standard.)
Sugar, sure and sumac are the only three in Modern English, but
historically there were others. In the sixteenth century a phonetic
change of sy- to sh- was attested (in the shape of sh- misspellings)
not just in the words sugar and sure, but also in words like suit
(variously spelled shute, shutte, shuite and shuett), suet (spelled
showitt, shewet and shuet) and sue (spelled shue). By the nineteenth
century, the sy- pronunciations won out for all but sugar, sure and
sumac (and was later replaced by plain old s-), though the sh-
pronunciation also survived in the middle of some words like issue,
tissue, assure, ensure, insure, pressure, etc.
Another source I found that describes some of the history of this pronunciation is English Pronunciation in the Eighteenth Century: Thomas Spence's ‘Grand Repository of the English Language’, by Joan C. Beal (1999). According to Beal,
much of the seventeenth-century evidence for the palatalization of
preceding alveolar consonants [...] is from ‘vulgar’ or dialectal
sources: Cooper, for instance, in his semi-phonetic notation, lists
shugar with the [j] assimilated, as a ‘barbarous’ pronunciation. By
the end of the eighteenth century, this palatalization, with its
subsequent assimilation of the /j/, is accepted even by Walker in
sugar and with palatalization but not assimilation in sure, but
elsewhere it is heavily stigmatized, at least in stressed syllables.
Some dictionary authors, such as Sheridan, did list pronunciations with word-initial /ʃ/ for some other words, but these pronunciations were criticized by other orthoëpists:
We have already seen that the author of A Caution to Gentlemen Who
Use Sheridan’s Dictionary attacked Sheridan for his palatalizations
and, in our discussion of the words in Appendix 6a, that Sheridan had
more instances of palatalization than Spence or Burn before the
unstressed ⟨ure⟩ ending. It is certainly the case that Sheridan
admitted this palatalization of alveolars before earlier /juː/ to an
extreme degree: he has palatalization of /s/ to /ʃ/ with consequent
loss of following /j/ in all words with the prefix super-, whereas
Spence, Walker and Burn all have /sjuː/ here, and in all similar
words except sugar, sure and surety, in which /ʃ/ occurs in PDE. (150)
Interestingly, Beal considers it possible that this palatalization was a feature of Irish English (which would support the relevance of redbmk's answer):
The author of A Caution and, indeed, Jespersen (1909-49: 344, 347)
attribute Sheridan’s pronunciation of words such as tune and suicide
to interference from Irish English. In many cases, the accusation of
‘Irishism’ is a knee-jerk reaction from critics who simply did not
agree with Sheridan’s recommendations, but, in this case, there may be
some substance to it. Jespersen (1909-49: 347) points out that ‘B Shaw
writes Choosda and schoopid as Irish for Tuesday and stupid (John
Bull’s Isl. 12, 38)’. On the other hand, initial /tʃ/ and /ʃ/ for
/tj/ and /sj/ are attested in seventeenth century English (as opposed
to Irish) sources: Dobson (1957: 706-7) shows suit: Shute: shoot as
homophones in Hodges; and tulip: julip as well as dew: due: jew in
Brown (none of our sources shows initial /dj/ becoming /dʒ/). These
instances are, however, few and far between and in homophone lists,
which, as Dobson explains, often give more colloquial pronunciations.
If Sheridan’s palatalizations in supreme, tune etc. are not Irishisms,
perhaps they represent a more colloquial kind of London English.
However, she thinks it is more likely that these variants arose in London:
I am informed (Karen Corrigan, personal communication) that this
palatalization does occur in Irish, but only in the Ulster dialects,
so that it is very unlikely that the Dublin-born Sheridan would have
been influenced by it. What is more likely is that the palatalization
was a colloquialism common in London, which may have been widely used
in less careful speech, then as now. (150-151, note 33)
I'm not sure precisely what she means by "then as now." I have heard that some, perhaps even many, present-day British English speakers merge /tj/ into /tʃ/ (i.e. their "tune" sounds like "choon") and /dj/ into /dʒ/, but I haven't heard of any that have /ʃ/ where standard British English has /sj/ or /s/.
It's unclear why these words in particular show this change, and others don't in present-day English
I don't know of any explanation for why sugar and sure (and for some people sumac) ended up being pronounced with /ʃ/, but other words starting with ⟨su⟩ (such as suit and super) ended up being pronounced with /s/ by modern speakers.
Example words showing the variable outcomes of historical /sjuː/ and /zjuː/ in present-day English
Before a stressed syllable:
/s(j)/ or /z(j)/:
suit, assume, (resume, presume etc.) supreme, suture, exude, exuberant, esurient. I found a number of other words like these, many of them words starting with super-.
/ʃ/ or /ʒ/:
sugar, sure (surety, assure, ensure etc.), sumac (pronunciations with /ʃ/ and /s/ both exist), luxurious, luxuriant (these last 2 might have been influenced by luxury, which is stressed earlier), usurious (MW lists pronunciation with /z/ also; influence from usury seems plausible), caesura (MW lists pronunciation with /z/ also). I don't know of any other words like these.
Before an unstressed syllable:
/ʃ/ or /ʒ/: pressure, fissure, seizure, treasure, enclosure, exposure, usury, censure, tonsure, licensure, azure, sensual, sensuous, sexual, flexuous. I found a number of other words like these, many of them nouns with the suffix -ure.
/s(j)/: insulate, insular, peninsula, insulin, consulate, consular, capsule, encapsulate, Ursula. There are a few more words I've found like these.
variation between /s(j)/ and /ʃ/ and/or /z(j)/ and /ʒ/: exudate, exudation, lapis lazuli, mensurable, mensural, commensurate.