How to filter results of a query
Your CTE:

(
  SELECT a.gid,
         ... AS the_geom  
  FROM ...
) 


produces a table with 2 columns, named gid and the_geom. But the "wrap" has an obvious glitch, it only has one column:

WITH data (the_geom) AS


So it says that the table will be named data and the first column (re)named to the_geom. Now you have 2 columns named the_geom! You could have the same effect - but more clear to spot - if you had written:

WITH data (the_geom, the_geom) AS


The solution is simple. Either remove the column list from that part:

WITH data AS
  ( ...
  )


or (re)name both columns explicitly:

WITH data (gid, the_geom) AS           -- explicit
(
  SELECT a.gid,
         ... AS the_geom  
  FROM ...
) 
INSERT INTO public.g100_wby_lakes_r (gid,geom) 
SELECT gid, the_geom 
FROM data 
WHERE st_GeometryType(the_geom) = 'MULTIPOLYGON' ;