The short answer is "yes".
There is U.S. Supreme Court authority that supports this position, In particular, United States v. Laub, 385 U.S. 475 (1967), Cox v. Louisiana, 379 U.S. 599 (1965), and Raley v. Ohio, 360 U.S. 423 (1959), stand for the proposition that a defendant may not be punished for actions taken in good faith reliance upon authoritative assurances that he will not be punished for those actions.
If the U.S. Department of Justice (or a U.S. Attorney with jurisdiction over the place the offense was committed) (hereinafter DOJ) says this, people who reasonably rely on that pronouncement can't be prosecuted until a different policy is announced and people who acted in reliance on the previous DOJ position are given a reasonable opportunity to change their conduct in response to the newly announced policy. The statement does have to be a publicly announced policy (or a policy personally communicated to the defendant or his counsel), and not just a de facto reality in terms of prosecutions not being brought in the past, or a secret, unannounced policy (or, for example, an unofficial and offhand statement of the U.S. Attorney General at a party that does not amount to a policy statement).
Of course, the defense doesn't protect you if the DOJ says it won't prosecute if you do X, but you do X times Y which goes beyond the safe harbor created by the DOJ pronouncement.
For example, the DOJ might say that they will not prosecute conduct involving marijuana offenses that is legal under state law, if it does not violate any other laws, and also meets certain conditions found in federal law (e.g. no offenses within 1000 feet of a school) that the DOJ chooses not to refrain from enforcing.
But, if the DOJ then publicly says that it will start enforcing federal law without exceptions on July 1, 2021 and has rescinded its prior policy, a reasonable time in advance, then this defense ceases for conduct after that date. What constitutes reasonable notice would depend upon the facts and circumstances.
The DOJ can also reach a binding agreement not to prosecute a particular instance of conduct by a particular person irrevocably in connection with plea bargaining type agreements, with respect to offenses of which the DOJ has jurisdiction (but not necessarily prosecutions by a different government such as a state government or the government of another country, for which the DOJ is not an authorized representative).
For example, suppose that a mail carrier is killed by a resident of a home claiming to have acted in self-defense in Denver, Colorado. The DOJ could reach an irrevocable agreement with the resident to accept a plea bargain to a misdemeanor charge of not paying the tax due on the sale of the firearm from a non-compliant gun shop, dismissing forever the charge of murder of a federal post office employee. But that agreement would not bar the District Attorney in Denver from bringing murder charges twenty years later under state law prohibiting murder of human beings in the State of Colorado. For the defendant resident to prevent that from happening definitively, an agreement from the State of Colorado's District Attorney in Denver, or the Colorado Attorney General, would also be required.