While Upgrading/Downgrading HDP in Ambari, if you see "Unable to determine the stack and stack version" it is possible the repo version has some inconsistency.
Post Ambari2.6.x, should have repo_version table "resolved" column as 1 - If it shows "0" then run below update query.
update repo_version set resolved = 1
Re-start Ambari and then attempt the operation again - it should go through.
Note: As of now it is not a BUG as we could not able to reproduce the issue.