This depends on several factors, but primarily the foundation of mathematics you're working over.
The most common framework for mathematicians to be working in these days is a theory of sets, described by a collection of axioms known as the Zermelo-Fraenkel axioms, or ZF for short. Often this is called ZFC because people also toss in the axiom of choice. I like to write ZF(C) to leave open the possibility of neglecting choice ;p
Working in ZF(C) set theory, everything is a set. All mathematical objects and concepts, be they numbers, functions, or complex structures are ultimately defined in terms of sets. There is only one notion of equality in ZF(C) set theory, which is that we write $X=Y$ for two sets $X$ and $Y$, if and only if $\forall x\in X, x\in Y$ and $\forall y\in Y, y\in X$.
For example, in David's comment, he mentions the example of $\sqrt{4}=2$. While this isn't often mentioned at the start of one's mathematics education, here $\sqrt{4}$ and $2$ are really shorthands for sets (being Cauchy sequences of rational numbers!), and the equality there is really a set equality.
So, that makes (more) precise your first definition of equality, what about the second one? Well, this also depends on several factors, such as what you mean by "distinct" and "having all of the same properties". Again, if we're working in ZF(C) then to say that two sets $X$ and $Y$ are distinct typically means that $X\neq Y$.
What does it mean to say they satisfy all of the same properties? Well, in my opinion, the most sensible interpretation is that for any well-formed statement $P(a)$ ranging over sets, $P(X)$ is true if and only if $P(Y)$ is true. Now consider the statement:
"$P(a): a = X$"
Certainly $X=X$, hence $P(X)$ is true, and since "$X$ and $Y$ satisfy all the same properties" it must be that $P(Y)$ is true, ie. $X=Y$. However, this is a problem, because we're assuming that $X\neq Y$. So, in short, it's not possible to have "distinct" objects satisfying "all the same properties". In other words, if two objects satisfy all the same properties, then they are in fact equal.
Now, you might disagree with my interpretation of terms like "distinct" and "all the same properties in common", but I think I've given the most straightforward and reasonable approach to this. If you have something else in mind, then the onus is on you to provide precise and rigorous definitions of these concepts.
It is, however, important to note that there are different notions of "sameness" other than set equality. In many disciplines, mathematicians don't care about strict equality, but rather the notion of isomorphism which is when for two objects $X$ and $Y$, there are some structure-preserving maps $f:X\to Y$ and $g:Y\to X$ where $f\circ g$ is the identity map on $X$ and $g\circ f$ is the identity map on $Y$. In many fields, such as group theory and topology, isomorphism is the notion of sameness that mathematicians ultimately care about, and are only interested in those properties which are preserved by isomorphism.
There are other notions of sameness still. It's far too much to begin to explain in one post here (let me shamelessly plug this video I made about it), but there's a new-ish foundation of mathematics called Homotopy Type Theory, which has as an axiom that equivalence is equivalent to equality! (I'm somewhat imprecise here, apologies to any experts reading this)
You're correct that this ventures into very deep philosophical waters, there's much more to say about this topic! I hope this gets you started on your journey of thinking about equality and sameness. You might also find this incredible talk by Dr. Emily Riehl enlightening.