These two sentences involve different analyses, which can be shown by using the following test: replacement of the infinitive (clause) by the neuter pronoun hoc. In the first example the infinitival clause te dormire can be replaced by hoc, whereas in the second example it is only the infinitive spirare that can be replaced by this neuter pronoun.
Iam necesse est hoc (i.e. te dormire)
Hoc (i.e. spirare) necesse est homini.
So notice that in the first sentence the accusative pronoun te is an argument of dormire (te is the subject of this infinitive), whereas in the second one the dative noun homini is an argument of necesse est (homini is the indirect object of necesse est).
EDIT (motivated by the comments below):
I agree with gaufridus when saying:
Recast with a gerund, the sentences seem more obviously distinct: necesse est te dormire 'your sleeping is necessary' and necesse est tibi dormire 'sleeping is necessary for you' (even if the sense is somewhat changed, it makes the difference more obvious to an Anglophone).
Concerning the English translation of an Acc. cum Inf. construction like Necesse est te dormire as 'It is necessary for you to sleep', it is worth noting that some scholars have claimed that the assignment of the accusative case te in this Latin example is carried out by a null (prepositional-like?) complementizer similar to "for" in English constructions like For him to invite Mary would be stupid (please see page 25 of their paper downloadable at this link). Following gaufridus's relevant parallelism, cf. the latter sentence with His inviting Mary would be stupid.
It is then important to point out that in Latin the accusative case of the subject of the infinitive is not necessarily assigned by the main verb. E.g. see the discussion in this link concerning how the accusative case can be assigned in examples like Video te (dormire), Dico te dormire, and Necesse est te dormire. In particular, the discussion of the last example (where the main verb is not transitive) is mainly relevant for Charo's question.
As for tony's comment, it is important to realize that Iam necesse est te dormire and Iam necesse est tibi dormire involve different analyses: cf. above Iam hoc necesse est (hoc = te dormire) and Iam hoc necesse est tibi (hoc = dormire). As noted, the dative tibi is not the subject of the infinitive dormire but the indirect object of necesse est.
Still, one (e.g. tony) can wonder why it is then the case that the sentence with the dative can have a translation that is similar to the one with the 'Accusativus cum Infinitivo'. The answer is that the dative (e.g. tibi above) is coreferent with the null subject of the infinitive: i.e. the "dative of interest" tibi, which grammatically depends on necesse est, is coreferent with the implicit agent of the infinitive dormire. Technically speaking, tibi is said to be the controller of the null/PRO subject of the infinitive.
Let me conclude this discussion with a comparison of the two following examples, which are very often treated as synonymous in many Latin grammars:
Iam necesse est tibi dormire.
Iam tibi est dormiendum.
One could say: "you, Mitomino, have just told us that in the former example tibi is not the agent of dormire. Assuming that both examples are synonymous, should/could one then conclude that tibi is not really an agent (cf. the traditional term "dative of agent") either in the latter sentence?"
Short answer: Yes, that's right! Despite appearances (and despite what grammatical tradition has told us), tibi is NOT the grammatical agent in Iam tibi est dormiendum. Those of you who are interested in knowing why tibi has not been grammatically construed as an agent in this construction, take a look at the two following references [NB: these two texts are quite readable since their authors don't use a technical vocabulary].
Suárez Martínez, P. M. (2001). "Le datif d’agent (datiuus auctoris). Un fantôme dans la syntaxe latine." In C. Moussy (Ed.). De Lingua Latina Novae Quaestiones. Actes du Xè Colloque International de Linguistique Latine (pp. 597-607). Louvain/Paris/Sterling,Virginia: Peeters. Downloadable at https://www.unioviedo.es/pmsuarez/Articulos_files/Le%20datif%20agent.pdf
Danesi, S., C. Johnson & J. Barðdal. (2017). "Between the Historical Languages and the Reconstructed Language: An Alternative Approach to the Gerundive + “Dative of Agent” Construction in Indo-European." Indogermanische Forschungen 122 (1): 143–188.
Downloadable at https://www.researchgate.net/publication/320958533_Between_the_Historical_Languages_and_the_Reconstructed_Language_An_Alternative_Approach_to_the_Gerundive_Dative_of_Agent_Construction_in_Indo-European