As someone who’s been on the hiring side there are some legalities involved on what to answer here. But I’ve always made a point of telling people who asked why. However I’m not in HR, so lots of people might get filtered before I even got a chance to interview them.
Also we asked candidates to do a take home and we talked about their solution during the interview, so most people got a good understanding of why they were rejected, but a couple of times people asked afterwards and I replied to them with the reasons we considered they were not at the level we were looking for, but that we would keep them in consideration for a more junior role if there ever was an opening.