Is there any word or phrase for when someone in fact says the truth while intends to lie?

Solution 1:

I would call this an accidental truth. TV Tropes defines it as:

It looks like a character is going to get caught out in a lie that they told, but then they're unexpectedly saved—they didn't know it, but what they said was correct all along.

TV Tropes

This definition is obviously about the trope from film and TV, but the concept easily extends.

An alternative phrase is inadvertent truth, which has quite a bit of currency. It usually denotes, I believe, something accidentally revealed.

Solution 2:

Warning: philosophy; does not necessarily match with all dictionary definitions of untruthful, but certainly with some.

Untruthful truth, also: a lie.

(L1) To lie =df to make a believed-false statement to another person with the intention that the other person believe that statement to be true.

[...]

According to the untruthfulness condition, lying requires that a person make an untruthful statement, that is, make a statement that she believes to be false. Note that this condition is to be distinguished from the putative necessary condition for lying that the statement that the person makes be false (Grotius 2005, 1209; Krishna 1961, 146). The falsity condition is not a necessary condition for lying according to L1.

[...]

Statements that are untruthful may be true. In Jean-Paul Sartre’s short-story, The Wall, set during the Spanish Civil War, Pablo Ibbieta, a prisoner sentenced to be executed by the Fascists, is interrogated by his guards as to the whereabouts of his comrade Ramon Gris. Mistakenly believing Gris to be hiding with his cousins, he makes the untruthful statement to them that “Gris is hiding in the cemetery” (with the intention that they believe this statement to be true). As it happens, Gris is hiding in the cemetery, and the statement is true. Gris is arrested at the cemetery, and Ibbieta is released (Sartre 1937; cf. Siegler 1966: 130). According to L1, Ibbieta lied to his interrogators, although the untruthful statement he made to them was true, and he did not deceive them about the whereabouts of Gris (Isenberg 1973, 248; Mannison 1969, 138; Lindley, 1971; Kupfer 1982, 104; Faulkner 2013).

Taken from, and full explanation there, https://plato.stanford.edu/entries/lying-definition