For the cupcakes: Preheat the oven to 350 degrees F. Line two 12-cup muffin tins with paper liners and spray with cooking spray. Whisk the flour, cocoa powder, baking powder, baking soda and salt in a medium bowl; set aside. Whisk the buttermilk, food coloring and vanilla in a spouted measuring cup; set aside.
Beat the granulated sugar and butter in a stand mixer (or a large bowl if using a hand mixer) on medium speed until very light in color and fluffy, about 5 minutes, scraping down the sides of the bowl as needed. With the mixer still on medium, slowly add the eggs and beat until fully incorporated. Reduce the speed to the lowest setting; with the mixer running, add 1/3 of the flour mixture, then 1/2 of the buttermilk mixture, then 1/2 of the remaining flour mixture, then the remaining buttermilk mixture, then the remaining flour mixture. Scrape down the sides and beat until well mixed. Fill the prepared liners about 3/4 full of batter. Bake until the cupcakes bounce back when pressed and a toothpick inserted in the center comes out clean, 20 to 22 minutes. Let cool in the pan for a few minutes, then transfer to a rack to cool completely.
For the frosting: Put the flour in a small saucepan. Vigorously whisk in about 1/2 cup milk, making sure to get the whisk into the edges of the pan, until you have a smooth, thick paste. (This step keeps the flour from clumping.) Slowly whisk in the remaining milk until fully incorporated and the mixture is smooth. Cook over medium heat, whisking constantly, until the mixture is very thick, about 5 minutes. (Toward the end of the process, the mixture will become a thick paste; it may seem to be forming lumps, but whisk vigorously and the lumps will disappear.) Scrape into a bowl, press plastic wrap onto the surface and refrigerate until cool, about 45 minutes.
Using a stand mixer fitted with the paddle attachment (or a hand mixer), beat the butter and granulated sugar on medium speed until very light and fluffy, about 5 minutes. Add the cooled flour mixture a tablespoon at a time and beat until smooth. Switch to the whisk attachment (or continue with the hand mixer), add the vanilla, salt and 3 to 5 drops green food coloring and whip until very light and fluffy, like thick whipped cream, up to 10 minutes with a stand mixer or 12 minutes with a hand mixer.
To assemble: Using a sharp serrated knife, cut 3 cupcakes in half vertically, gently sawing through the paper liners; set aside. Frost the remaining cupcakes. Put the sanding sugar on a small plate and roll the edge of each cupcake 3/4 of the way around in the sugar, making a green border around each with a gap on one side. On a large serving platter, arrange 18 cupcakes in groups of three, pushing them together at the gaps, to make 6 shamrock cakes. Dip the tops of the cupcake halves in sugar and wedge a pointy end of 1 half between 2 of the cupcakes in each group to form the stems.