No, you cannot change node’s config/state flag dynamically. You can do something that may look a bit like what you are trying to achieve using when:
leaf A {
type boolean;
default true;
}
container config {
when '../A = "true"';
leaf B {
type string;
}
}
container non-config {
when '../A = "false"';
config false;
leaf B {
type string;
}
}
If that does not solve your problem, try to describe your use-case in more detail, maybe there are other ways to approach it.