All you have to do is to
Pivot[
^] data.
This should do the trick:
SELECT Department, [Male], [Female]
FROM (
SELECT Department_Name As Department, P_Gender
FROM Vw_IPDPatDetails
WHERE DischageStatus='Y' AND (E_date between '8/1/2019' AND '8/31/2019')
) AS DT
PIVOT(COUNT(Department) FOR P_Gender IN ([Male], [Female])) AS PT