As a preface to my answer, I have to stress that this is not really a settled area of law, and so it's impossible to give a confident answer. I can at best give my theory. A reader would need to consult with a good lawyer before going down this route.
There are three types of infringement that are at issue here: direct infringement (35 USC § 271(a)), induced infringement (35 USC § 271(b)), and contributory infringement (35 USC § 271(c)).
For the sake of argument, let's say there is a valid, granted patent with a claim "a method comprising performing algorithm X". Distributor D distributes the source code for algorithm X. Performing algorithm X infringes the patent.
Does D directly infringe?
No. A method claim requires that the method be performed for the claim to be infringed (per Limelight Networks, Inc., v. Akamai Technologies, Inc., et al, 134 S. Ct. 2111 (2014)). Source code itself does not perform the method, it simply contains instructions for doing so. Therefore D does not directly infringe the patent.
Does D actively induce infringement?
35 USC § 271(b) provides:
Whoever actively induces infringement of a patent shall be liable as an infringer.
Inducement infringement can only exist if there is direct infringement (per Aro Mfg. Co. v. Convertible Top Replacement Co., 365 U. S 336, 341 (1961)). Thus it must be shown that somebody executed the source code to infringe the method itself.
It must also be shown that D had "specific intent to encourage another's infringement and not merely … knowledge of the acts alleged to constitute inducement" (Manville Sales Corporation v. Paramount Systems, Inc., 917 F.2d 544 (Fed. Cir. 1990)). Simply distributing source code is therefore probably not enough. Therefore D does not actively induce infringement in the patent.
Does D perform contributory infringement?
35 USC § 271(c) provides:
Whoever offers to sell or sells within the United States or imports into the United States a component of a patented machine, manufacture, combination or composition, or a material or apparatus for use in practicing a patented process, constituting a material part of the invention, knowing the same to be especially made or especially adapted for use in an infringement of such patent, and not a staple article or commodity of commerce suitable for substantial noninfringing use, shall be liable as a contributory infringer.
The source code is an apparatus for use in practising the algorithm. It is material (since it contains all the instructions needed), it's especially made (since it only performs the one method), and is not a staple (since it has no other use). If the
However, contributory infringement requires knowledge of the patent (Hewlett-Packard Co. v. Bausch & Lomb, Inc., 909 F.2d 1464, 1469 n.4 (Fed. Cir. 1990)).
So the answer would seem to be:
D infringes by distributing the source code if they know about the patent, and they sell the source code, and the source code is used by someone to infringe the patent.
Would a Beauregard claim change the position?
A Beauregard claim is of the form "a non-transitory computer-readable medium having instructions which, when executed by a processor, cause the processor to perform algorithm X".
If D stored the source code (instructions) on the hard drive of your computer (a non-transitory computer-readable medium), it would seem that they would infringe the patent without anything more (though defences may apply). Distributing would be a further direct infringement.
Such is the strength of Beauregard claims that they are generally included in most modern software and business method patent applications.
So how does LAME get around this?
In the US, they are basically relying on experimental use defence to infringement. Although their application of it has not been tested, the exception is very limited. Per Madey v. Duke University, 307 F.3d 1351 (Fed. Cir. 2002):
In short, regardless of whether a particular institution or entity is engaged in an endeavor for commercial gain, so long as the act is in furtherance of the alleged infringer's legitimate business and is not solely for amusement, to satisfy idle curiosity, or for strictly philosophical inquiry, the act does not qualify for the very narrow and strictly limited experimental use defense.
Maybe D could rely on this. But I would expect that distributing (as opposed to solo tinkering) is probably beyond amusement, idle curiousity and philosophical inquiry, and would probably not be able to use the defence.