Let $\mathcal{C},\mathcal{D}$ two $\infty$-categories and $f:\mathcal{C}\to\mathcal{D}$ and $g:\mathcal{D}\to \mathcal{C}$ two functors.
Recall (HTT.5.2.2.7) that a natural transformation $u:1_{\mathcal{C}}\to gf$ is a unit transformation if the natural transformation $$(\ast)\qquad\mathrm{Map}_{\mathcal{D}}(f-,-)\to \mathrm{Map}_{\mathcal{C}}(gf-,g-)\xrightarrow{u^*}\mathrm{Map}_{\mathcal{C}}(-,g-)$$$$(\ast)\qquad\mathrm{Map}_{\mathcal{D}}(f-,-)\xrightarrow{g} \mathrm{Map}_{\mathcal{C}}(gf-,g-)\xrightarrow{u^*}\mathrm{Map}_{\mathcal{C}}(-,g-)$$ is an equivalence.
Theorem A natural transformation $u:1_{\mathcal{C}}\to gf$ is a unit transformation if and only if there is a natural transformation $e:fg\to 1_{\mathcal{D}}$ satisfying the triangular identities.
Proof:
Let us first show that if such an $e$ exists, then the natural transformation $(\ast)$ is an equivalence. Indeed we will show that the natural transformation $$(\ast\ast)\qquad\mathrm{Map}_{\mathcal{C}}(-,g-)\to \mathrm{Map}_{\mathcal{D}}(f-,fg-)\xrightarrow{e_*}\mathrm{Map}_{\mathcal{D}}(f-,-)$$$$(\ast\ast)\qquad\mathrm{Map}_{\mathcal{C}}(-,g-)\xrightarrow{f} \mathrm{Map}_{\mathcal{D}}(f-,fg-)\xrightarrow{e_*}\mathrm{Map}_{\mathcal{D}}(f-,-)$$ is an inverse. Indeed, if $l:fc\to d$ is an arrow in $\mathrm{D}$, the transformation $(\ast)$ sends it to $gl\circ u_{c}$. Then, $(\ast\ast)$ sends it to $$e_{d}\circ f(gl\circ u_{c})\cong e_{d}\circ fgl \circ fu_{c}\cong l\circ e_{fc}\circ fu_c \cong l$$ where the second equivalence is the naturality of $e$ and the third is one of the triangular identities. So $(\ast\ast)$ is a left inverse of $(\ast)$. The dual proof (using the other triangular identity) implies that it is a right inverse too, so that $(\ast)$ is an equivalence.
Let us now prove the other direction. if $(\ast)$ is an equivalence, in particular, the map $$\mathrm{Map}_{\mathcal{D}}(fg-,-)\cong\mathrm{Map}_{\mathcal{C}}(g-,g-)$$ is a natural equivalence. By taking ends, there is an equivalence of the space of natural transformations $$\mathrm{Nat}(fg,1_{\mathcal{D}})\cong \mathrm{Nat}(g,g)$$$$\mathrm{Nat}(fg,1_{\mathcal{D}})\cong \mathrm{Nat}(g,g)\,.$$ Let $e:fg\to 1_{\mathcal{D}}$ be the natural transformation corresponding to $1_g:g\to g$ under this equivalence. I claim that this satisfies the triangular identities.
In fact, for every $d\in\mathcal{D}$, the arrow $e_d$ has been chosen so that there is an equivalence $$(ge_d)\circ u_{gd}\cong 1_{gd}$$ naturally in $d$. So one triangular identity is satisfied. On the other hand, arguing as in the previous direction, this implies that $(\ast\ast)$ is a right inverse of the map $(\ast)$. Since that was an equivalence, it must be a left inverse too, Choosing $l=1_{fc}$, this shows $e$ satisfies the second triangular identity. $\square$
If I understood the question in the comments, your doubt can be boiled down to the following construction: Ifif $\mathcal{C},\mathcal{D}$ are two $\infty$-categories, $F,G:\mathcal{C}\to\mathcal{D}$ two functors and $e:F\to G$ a natural transformation, how can we constructthere exists a natural commutative diagram of the form $$\require{AMScd} \begin{CD} \mathrm{Map}_{\mathcal{C}}(-,-) @>{F}>> \mathrm{Map}_{\mathcal{D}}(F-,F-)\\ @V{G}VV @V{e_*}VV \\ \mathrm{Map}_{\mathcal{D}}(G-,G-) @>{e^*}>> \mathrm{Map}_{\mathcal{D}}(F-,G-); \end{CD}\,.$$$$\require{AMScd} \begin{CD} \mathrm{Map}_{\mathcal{C}}(-,-) @>{F}>> \mathrm{Map}_{\mathcal{D}}(F-,F-)\\ @V{G}VV @V{e_*}VV \\ \mathrm{Map}_{\mathcal{D}}(G-,G-) @>{e^*}>> \mathrm{Map}_{\mathcal{D}}(F-,G-) \end{CD}\,.$$
In order to construct this we notice that the pullback of the right bottom corner of the diagram is just the functor $\mathrm{Map}_{\mathcal{D}^{\Delta^1}}(e-,e-)$ where we interpret the natural transformation $e$ as a functor $\mathcal{C}\to \mathcal{D}^{\Delta^1}$, sending $c$ to $Fc\to Gc$ (this is just the usual formula for mapping spaces in functor categories using ends, in this case applied to the functor category $\mathcal{D}^{\Delta^1}$). But then giving the required square is just equivalent to giving a mapnatural transformation $$\mathrm{Map}_{\mathcal{C}}(-,-)\to \mathrm{Map}_{\mathcal{D}^{\Delta^1}}(e-,e-)\,.$$ But this is justAnd we can simply choose the standard map induced by the functoriality of $e$.