I see similar mess, and have not gotten around to complaining about, and really not gotten to fixing it :-)
In my case, things are ok over ssh. But I have problems on a netbsd-10 bare metal install on an old (2008?) macbookpro, that I believe to be basically ok. Sounds like mlelstv has explained the woes. I wonder if we should make pgskrc sudo default to not doing this pty thing. I believe it is new behavior arriving in pkgsrc in the last 6-12 months, very fuzzily.