After they're neutered or spayed, many male and female dogs continue to mount and even masturbate because they have learned that the behavior feels good.
Often, during courtship, females in heat mount and hump their male "suitors." Female dogs also commonly mount and hump other females when one or both are in heat.