When a body spins around another body due to gravity and maintains a consistent orbit, we can know clearly two things about the body:
1. The speed of the orbit
2. The average radius of the orbit
Think about it. The Moon spins around the Earth due to gravity of the Earth. Right? And it's orbit always stays the same(when averaged). For it to stay in this balance where it isn't flying away from the Earth, requires that it be traveling at a speed and distance that equal out the effect of gravity on the object. So by knowing this speed(orbital speed) and distance(orbital radius), we can determine something very useful about the gravitational effect of the Earth on the Moon. From the gravitational effect, we can then determine the mass of the Earth.
Finding the mass of the Earth otherwise is quite difficult because we don't know exactly what is inside, and there are too many factors involved. We can't just put the Earth on a big scale. Also, determining it from gravity is flawed because there are too many factors that cause high uncertainty(Earth is not a perfect sphere, the moon exhibits gravity too, atmospheric pressure, centrifugal force, etc.). BUT we DO know the distance of the Moon from the Earth very accurately using Trigonometry. We also know the time the Moon takes to go around the Earth as we can easily measure this(lunar cycle). So if you take the orbital speed squared and multiply it by the orbital radius of the Moon's spin around the Earth, you obtain the Geocentric Gravitational Constant of the Earth.
Using that constant, we can determine the mass of the Earth. But we also need to know the Gravitational Constant(G) to make this determination. However, G has been difficult to determine with a high level of certainty. This is because the experiments to determine G have so far given inconsistent results. Either G is changing OR the factors in the experiments have not all been ruled out, likely the latter. You can read more on Geocentric Gravitational Constant here: https://en.wikipedia.org/wiki/Standard_gravitational_parameter