You define the CTE but then ignore it and select from the base table anyway.
It should be
WITH CTE
AS (SELECT [DepartmentName],
[Gender],
[BaseRate]
FROM [AdventureWorks].[dbo].[DimEmployee])
SELECT [DepartmentName],
[M],
[F]
FROM CTE PIVOT (Avg(BaseRate) FOR [Gender] IN ([M], [F])) AS P