Are you allowed to sell programs built in processing/p5.js?
The licenses for both Processing and P5.js are available on their respective GitHub pages. I’d start by reading through those.
You should also read through the Processing FAQ.
Short answer: yes you can use Processing or P5.js in commercial applications. And although not strictly legally required, you should provide a link back to Processing or P5.js, something like a “powered by Processing” link at the bottom of your page.
The official license for processing is here:
…and begins: “We use GPL v2 for the parts of the project that we’ve developed ourselves. For the ‘core’ library, it’s LGPL, for everything else, it’s GPL.”
As @KevinWorkman points out, the Processing FAQ. also contains a relevant entry:
Do I have to cite Processing? Do I have to share my code? Can I distribute my sketches?
We like it when people include a “Built with Processing” note with a link back to the site, since it helps create interest and brings in more people to the project. We don’t/can’t/shouldn’t require it, but it makes us happy because the project is free and this is one way you can help give back to us.
You can also remove the source code from web pages that you export, but in the spirit of the Processing project overall, we include it by default so as to encourage sharing and learning from one another.
You can distribute your sketches all you want, and commercial projects are just fine too, however we place no warranty on the software (see the download page for the license shenanigans).