You are mixing things up. As far as calculus on ##\mathbb{R}^{3}## is concerned, if ##X## is a smooth vector field defined on a simply connected region in ##\mathbb{R}^{3}## and ##\nabla \times X = 0 ## then there exists a smooth scalar field ##\varphi ## such that ##X= \nabla\varphi ## on that simply connected region. However if the vector field is defined on a non-simply connected region then this need not hold true.

If the curl of the vector field is non-zero, how can the vector field be the gradient of a scalar field?

EDIT: Note that we make use of the above in electromagnetism all the time because the electromagnetic field ##F## satisfies ##dF = 0 \Rightarrow F = dA## (at least locally) and we call ##A## the electromagnetic 4-potential.

If the curl is zero, then that GUARANTEES that there IS a potential function

No. But this is a very tricky subject. A lot depends on the domain of the vector field ##X##. For example, if ##X## is defined on entire ##\mathbb{R}^3##, then it's true: if ##curl(X)=0##, then there is a potential function. But if ##X## is defined on ##\mathbb{R}^3\setminus \{0\}## (for example), then there are counterexamples.

The Poincare lemma states that if the domain of definition of ##X## is convex (or more generally: star shaped), then it is true that if the curl is zero, then there is a potential function. But on more general domains, this might fail.

The study of this question is done in De Rham cohomology. This is a formalism set up to study the situations when ##curl(X)=0## implies the existence of a potential function.

If the curl is non-zero, then that GUARANTEES that there is NO potential function