Embryo implantation occurs when the embryo nests in the endometrium. This marks the beginning of the pregnancy and leads to the release and, therefore, increase of the hormone beta-hCG. When a chemical pregnancy occurs, implantation and increase of beta-hCG occurs, but after a few hours or days, the embryo's development stops and the release of beta-hCG ceases, which leads to a decrease in its level in the mother's blood.
Pregnancy tests detect the hormone hCG. Therefore, in the case of a chemical pregnancy, the pregnancy test is first positive (due to the increase in beta-hCG) and, after pregnancy loss, the test is negative due to the decline in beta-hCG.